Last active
January 23, 2016 16:14
-
-
Save mrahul17/95e07a651b82bbfdb28e to your computer and use it in GitHub Desktop.
scikit-learn utility scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # train-test split | |
| from sklearn.cross_validation import train_test_split | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4) | |
| #get accuracy score | |
| print metrics.accuracy_score(y,predict_y) | |
| #get optimum value of k in knn | |
| k_range = range(1,26) | |
| scores = [] | |
| for k in k_range: | |
| knn = KNeighborsClassifier(n_neighbours=k) | |
| knn.fit(X_train,y_train) | |
| y_pred = knn.predict(X_test) | |
| scores.append(metrics.accuracy_score(y_test,y_pred)) | |
| plt.plot(k_range,scores) | |
| plt.xlabel('value for k in knn') | |
| plt.ylabel('tesring accuracy') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment