Created
July 10, 2018 13:59
-
-
Save kohnakagawa/8f6b1ddcc0ed36adffafcbdb6d171fba to your computer and use it in GitHub Desktop.
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
| from sklearn.datasets import load_iris | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.neural_network import MLPClassifier | |
| from sklearn.externals import joblib | |
| import pandas as pd | |
| import numpy as np | |
| def main(): | |
| # example of MLP | |
| iris = load_iris() | |
| x = iris.data | |
| y = iris.target | |
| x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=0) | |
| clf = MLPClassifier(solver="sgd", random_state=0, max_iter=10000) | |
| clf.fit(x_train, y_train) | |
| print(clf.score(x_test, y_test)) | |
| # dump model | |
| joblib.dump(clf, "model.pkl") | |
| # load model | |
| clf2 = joblib.load("model.pkl") | |
| # classify | |
| print(clf2.score(x_test, y_test)) | |
| data = pd.read_csv("sample.csv") | |
| data['Sex'] = data['Sex'].map(lambda e: 1.0 if e == "female" else 0.0) | |
| print(data) | |
| print(data['Sex'].values) | |
| features = np.vstack((data['Sex'], data['Age'], data['Pclass'])).transpose() | |
| print(features) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment