2016年5月9日 星期一

開站囉

記錄一些資料的筆記
ipython3比python shell容易使用的shell替代品
不只可以使用[tab]自動補完,還可以將過程存檔
存檔指令%hist -f filename.py
附加指令%save -a filename.py 1-20

底下是一個嘗試的script



from sklearn.cross_validation import train_test_split

from sklearn import preprocessing

from sklearn import datasets

iris=datasets.load_iris()

X= iris.data[:, :2]

y=iris.target

X_train, X_test, y_train, y_test=train_test_split(X, y, test_size=0.25, random_state=33)

print(X_train.shape, y_train.shape)

scaler=preprocessing.StandardScaler().fit(X_train)

X_train=scaler.transform(X_train)

X_test=scaler.transform(X_test)

import matplotlib.pyplot as plt

colors=['red', 'greenyellow', 'blue']

for i in range(len(colors)):

    xs=X_train[:,0][y_train==i];

    ys=X_train[:,1][y_train==i]

    plt.scatter(xs, ys, c=colors[i])

  

plt.xlabel('Sepal length')

plt.ylabel('Sepal width')

plt.show()

沒有留言:

張貼留言