Skip to content

Instantly share code, notes, and snippets.

@harsha89
Created May 26, 2020 10:31
Show Gist options
  • Save harsha89/49c89a5d02a2d4106ad48535dcab2052 to your computer and use it in GitHub Desktop.
Save harsha89/49c89a5d02a2d4106ad48535dcab2052 to your computer and use it in GitHub Desktop.
# Data Manipulation libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
import joblib
df = pd.read_csv('tp3_boston_data.csv') # Load the dataset
df_x = df[['crim', 'zn', 'indus', 'chas', 'nox', 'rm', 'age', 'dis', 'rad', 'tax', 'ptratio', 'lstat']]
df_y = df[['medv']]
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(df_x)
df_x_scaled = scaler.transform(df_x)
df_x_scaled = pd.DataFrame(df_x_scaled, columns=df_x.columns)
X_train, X_test, Y_train, Y_test = train_test_split(df_x_scaled, df_y, test_size = 0.33, random_state = 5)
mlp = MLPRegressor(hidden_layer_sizes=(60), max_iter=1000)
mlp.fit(X_train, Y_train)
Y_predict = mlp.predict(X_test)
#Saving the machine learning model to a file
joblib.dump(mlp, "model/rf_model.pkl")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment