2019-03-14
TIL there a 3 types of Python programmer

  1. Use 2 spaces to indent.
  2. Use 4 spaces to indent.
  3. Use Tab to indent.

And they must hate each other.

Read More

2019-02-22
TIL Using Pickle to save sklearn model

The models in sklearn are objects, using Pickle to save and restore the trained classify or cluster models. Do not us numpy.save and numpy.load to do this, it’s not working.

An example:

1
2
3
4
5
6
7
8
9
10
11
12
13
import Pickle
from sklearn.cluster import Kmeans
# suppose we want to save this kmeans model
kmeans_results = KMeans(n_clusters=2).fit(X)
kmeans_results_file = "kmeans.pkl"

# saving results
with open(kmeans_results_file, 'wb') as f:
pickle.dump(kmeans_results, f)

# loading results
with open(kmeans_results_file, 'rb') as f:
kmeans_results = pickle.load(f)

Read More

2019-01-21
TIL python variables names cannot begin with a digit

C++ variables also cannot start with number. It’s a compiler issue, because a variable starts with number can be both a valid number or a variable…

Read More