Prepare and Fit Spatial Regression Models 20190222




Pay Notebook Creator: Roy Hyunjin Han0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [ ]:
# CrossCompute
measurement_table_path = 'measurements.csv'
target_folder = '/tmp'
In [ ]:
import pandas as pd
measurement_table = pd.read_csv(measurement_table_path)
In [ ]:
from sklearn import datasets
iris = datasets.load_iris()

Compare models

In [ ]:
from sklearn.linear_model import LogisticRegression
model1 = LogisticRegression(solver='lbfgs', multi_class='auto')
In [ ]:
from sklearn.svm import SVC
model2 = SVC(gamma='auto')
In [ ]:
import numpy as np
from sklearn.model_selection import cross_val_score
In [ ]:
model1_scores = cross_val_score(model1, iris.data, iris.target, cv=5)
np.mean(model1_scores)
In [ ]:
model2_scores = cross_val_score(model2, iris.data, iris.target, cv=5)
np.mean(model2_scores)

Fit model

In [ ]:
model = model2
model.fit(iris.data, iris.target)

Estimate values

In [ ]:
X = measurement_table.values
X
In [ ]:
y = model.predict(X)
y

Save results

In [ ]:
choices = 'setosa', 'versicolor', 'virginica'
In [ ]:
measurement_table['category'] = np.choose(y, choices)
In [ ]:
from os.path import join
target_path = join(target_folder, 'results.csv')
measurement_table.to_csv(target_path, index=False)
print('result_table_path = %s' % target_path)