Commit 0c73f140 authored by isurugunarathna's avatar isurugunarathna

Create Python model

parent a1c993d4
#import pandas
import pandas as pd
col_names = ['breed', 'age', 'weight', 'label']
# load dataset
pima = pd.read_csv("weight_data.csv", header=None, names=col_names)
print("===================")
print("Dataset head")
print("===================")
print(pima.head())
#split dataset in features and target variable
feature_cols = ['breed', 'age', 'weight']
X = pima[feature_cols] # Features
y = pima.label # Target variable
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=0)
# import the class
from sklearn.linear_model import LogisticRegression
# instantiate the model (using the default parameters)
logreg = LogisticRegression()
# fit the model with data
logreg.fit(X_train,y_train)
#
y_pred=logreg.predict(X_test)
# import the metrics class
from sklearn import metrics
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
print("===================")
print("Confusion matrix")
print("===================")
print(cnf_matrix)
print("===================")
print("Accuracy")
print("===================")
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
# print("Precision:",metrics.precision_score(y_test, y_pred))
# print("Recall:",metrics.recall_score(y_test, y_pred))
# Prediction test
y_prediction_test = logreg.predict([[12,3,48]])
y_labels = ["Overweight", "Normal", "Underweight"]
print(y_labels[y_prediction_test[0]])
5,4,22,1
12,15,20,0
12,2,19,2
6,4,36,2
2,15,8,1
8,9,44,0
11,1,11,1
11,15,31,1
5,7,22,1
14,13,5,1
1,14,27,1
10,13,32,1
14,15,21,1
6,6,9,0
1,10,32,0
12,3,48,1
10,4,48,0
9,13,24,0
3,15,28,2
13,2,40,2
14,13,25,1
9,1,33,0
6,14,33,1
9,5,6,1
8,2,3,0
2,10,2,0
4,3,31,1
15,13,15,1
4,7,45,0
13,14,18,0
14,14,46,2
12,10,7,2
12,13,21,1
9,15,6,0
6,8,34,2
11,15,32,0
7,8,46,0
11,4,29,2
1,1,5,2
11,5,43,1
6,10,19,0
10,15,30,1
6,12,25,0
12,6,45,2
11,13,49,1
4,2,36,1
15,2,43,2
5,15,36,0
6,14,11,1
14,9,40,1
7,11,34,1
8,5,47,1
5,2,44,0
2,2,40,0
1,8,35,1
2,2,39,1
5,13,15,1
6,6,9,2
11,11,13,1
3,10,33,2
2,9,7,2
2,1,24,0
3,2,40,1
1,3,21,2
12,5,8,0
9,6,17,0
8,11,27,0
2,1,50,0
3,11,25,0
7,11,30,2
11,8,21,0
3,15,12,1
15,3,39,1
5,14,30,2
8,10,43,1
12,4,50,1
7,13,29,0
7,11,18,2
3,2,31,0
10,14,37,1
14,13,19,1
1,8,22,1
2,6,13,2
8,15,33,1
13,10,27,0
14,13,33,2
14,4,6,2
2,12,26,1
2,5,16,1
7,14,3,2
13,8,26,0
13,7,49,2
1,12,38,1
1,13,13,2
13,2,35,2
12,1,8,0
5,14,5,1
12,7,41,1
9,13,35,1
13,1,49,1
1,15,49,0
11,12,11,0
4,15,44,1
1,14,25,2
12,14,4,1
9,7,49,0
14,1,23,1
8,12,35,0
13,5,22,2
10,6,7,1
10,7,8,2
15,15,18,1
2,14,41,2
4,3,32,1
1,5,14,0
6,7,8,1
7,9,36,1
8,4,4,0
3,13,14,0
3,9,32,1
13,15,28,2
15,12,46,1
7,11,36,0
7,14,50,2
10,12,31,0
7,13,48,1
7,4,22,2
11,13,15,0
7,7,20,2
5,12,33,0
13,14,2,0
4,7,46,1
3,15,18,0
13,1,21,1
5,10,38,2
7,10,41,1
3,2,35,0
5,10,42,2
1,7,43,2
14,14,42,0
13,15,28,0
6,5,23,1
9,1,46,2
4,3,49,1
15,1,13,2
2,1,47,2
14,5,14,0
1,4,2,2
8,8,24,1
13,11,9,2
3,3,16,0
10,9,46,0
5,5,37,0
9,1,44,0
10,10,19,2
12,8,31,2
14,12,45,1
6,7,46,0
7,14,19,2
13,5,32,1
10,15,22,0
11,2,34,0
1,4,13,0
9,12,25,2
7,5,14,0
9,4,20,0
4,4,37,1
6,3,7,1
8,15,33,0
5,13,43,2
3,2,40,2
15,9,7,1
13,2,15,2
1,13,7,1
9,13,13,2
8,13,12,2
7,14,47,0
2,2,49,0
5,9,21,2
5,12,38,2
12,5,13,0
15,5,27,1
11,7,48,1
5,14,27,2
12,2,23,0
1,14,8,2
14,13,50,2
10,11,14,2
5,14,14,1
15,13,41,0
7,5,45,0
2,12,33,0
2,15,40,1
12,12,2,1
2,12,37,1
7,14,25,2
12,7,13,1
10,8,8,1
12,11,39,0
7,12,15,2
2,4,7,0
3,10,3,0
1,1,46,1
9,1,4,1
11,13,33,0
15,1,34,1
9,1,29,0
6,3,39,0
11,5,45,2
14,15,44,0
3,10,11,0
11,6,20,2
10,6,45,2
8,1,24,1
2,11,49,1
7,7,14,0
13,11,35,0
15,2,6,0
9,4,35,2
13,12,50,0
12,13,23,1
2,7,47,1
10,2,36,2
2,5,32,0
1,7,18,2
10,3,32,2
8,10,22,1
2,5,4,1
2,3,6,2
13,1,38,1
1,6,30,0
15,1,46,1
3,2,8,1
15,3,29,2
12,2,30,0
5,14,31,0
9,10,48,1
5,14,46,0
11,7,17,0
12,9,2,2
3,4,32,0
8,14,46,0
10,14,5,1
7,8,5,1
13,11,23,0
11,2,26,2
9,4,11,1
3,4,47,0
12,13,19,2
2,5,44,0
8,8,4,0
15,12,27,1
13,6,17,0
10,2,11,0
1,15,19,0
6,12,10,2
15,7,33,1
14,8,29,1
12,12,10,0
10,13,34,2
5,5,29,0
13,2,14,0
13,7,11,0
6,4,24,0
15,2,44,1
7,1,33,2
2,7,2,0
1,10,44,2
14,4,21,0
12,5,23,0
5,6,37,0
8,14,21,0
1,2,48,1
2,3,41,2
10,4,11,2
6,3,20,0
4,1,24,1
14,14,29,1
12,9,31,2
12,8,49,0
15,1,14,2
6,11,42,2
8,6,7,2
15,4,50,0
7,6,44,1
4,6,35,0
11,2,50,2
8,6,21,0
1,10,47,2
14,11,23,2
13,4,48,2
7,9,11,2
11,2,28,0
14,12,34,2
11,8,48,0
3,2,3,2
6,13,34,2
14,11,17,2
7,5,19,2
15,13,10,1
9,2,15,1
2,11,36,2
9,3,43,2
1,9,36,2
11,1,3,1
8,7,2,0
11,12,31,1
3,7,38,1
13,1,47,2
8,12,39,0
12,8,26,1
12,13,44,2
5,13,22,1
1,8,42,1
11,9,3,0
15,11,10,0
9,4,12,2
11,12,36,1
15,7,8,2
4,6,42,0
4,11,17,2
2,14,10,1
10,3,7,0
13,9,14,2
4,8,26,2
3,2,35,2
6,1,4,2
4,5,47,2
6,11,21,1
1,8,37,0
7,5,9,2
9,4,4,0
14,2,45,2
6,11,4,0
2,3,35,2
15,9,15,0
3,12,42,1
6,6,46,2
5,12,50,2
1,3,16,0
5,9,44,1
4,1,37,0
2,12,6,0
15,4,38,0
6,3,26,2
15,6,24,0
14,11,46,2
7,10,16,1
3,1,9,2
9,8,7,2
5,9,41,2
7,2,2,0
7,12,15,0
15,10,2,1
14,6,42,0
6,12,49,2
2,8,48,2
7,1,16,2
10,3,39,1
9,13,49,1
10,9,9,1
10,10,14,2
8,10,16,0
14,13,17,0
14,8,26,2
8,10,6,0
5,14,32,1
3,9,14,1
9,2,2,1
2,3,42,2
5,10,40,2
6,2,33,1
9,7,31,0
10,13,39,0
2,14,49,0
11,2,25,0
10,9,22,0
8,4,40,1
13,1,9,2
5,2,18,0
1,12,3,1
5,7,38,0
7,12,6,2
6,13,14,0
3,12,3,0
10,1,25,2
4,6,5,2
2,15,24,0
14,2,22,0
4,9,50,1
3,5,45,2
9,5,18,1
12,14,48,0
13,11,39,1
8,14,39,0
13,6,15,1
4,14,45,2
12,11,44,0
11,2,14,0
12,3,16,0
13,15,43,0
5,3,11,2
4,15,25,1
7,7,48,2
5,4,7,2
6,13,50,2
4,8,41,1
6,15,49,0
9,1,22,0
3,13,35,2
3,14,40,0
13,2,23,0
2,10,27,2
14,4,21,0
10,2,29,1
3,11,13,0
2,11,42,0
4,4,40,2
10,11,26,2
11,9,11,2
4,5,29,2
2,11,15,0
11,7,9,0
12,11,28,1
3,15,41,0
12,5,23,2
8,2,2,0
8,14,44,1
12,15,40,0
5,2,14,2
3,15,44,1
2,12,4,1
7,14,24,2
7,13,41,0
5,14,25,0
5,8,47,0
5,4,37,1
5,12,27,1
13,5,9,2
12,2,6,0
7,9,6,1
2,11,2,2
10,9,30,1
6,12,20,0
11,1,31,1
13,5,25,0
9,15,41,1
8,9,23,1
4,6,24,2
15,1,29,2
10,2,5,0
12,14,24,0
10,6,3,1
6,3,23,0
11,9,23,1
2,3,15,1
5,4,42,2
1,3,41,2
2,1,42,1
10,7,15,0
10,12,18,0
3,5,10,0
13,7,49,1
11,7,6,2
12,8,32,1
15,8,50,1
13,8,27,1
3,3,43,0
4,5,48,2
3,13,3,2
8,3,2,2
7,10,6,1
8,1,16,1
14,7,39,0
8,14,8,1
4,13,8,0
11,2,8,1
3,13,23,0
15,13,44,1
8,12,9,0
14,6,41,0
5,15,12,2
8,13,25,0
4,11,7,1
9,9,46,0
3,3,41,0
4,1,20,2
14,12,37,2
2,4,13,1
12,6,4,1
7,13,28,1
9,15,45,0
5,5,49,0
11,4,37,0
14,13,17,1
3,8,48,1
1,9,30,0
1,2,6,0
6,3,42,0
13,3,27,0
10,5,24,2
11,9,41,0
1,5,7,2
15,2,47,2
15,1,22,0
9,12,50,1
13,11,41,2
10,7,16,1
14,12,46,2
10,7,7,2
13,14,21,2
4,9,15,2
14,15,43,2
2,12,9,2
6,11,18,0
14,7,28,0
9,9,21,0
4,3,7,1
6,10,26,0
2,3,32,2
15,10,3,2
1,5,41,2
7,11,48,0
10,14,47,0
12,8,3,1
4,7,41,1
4,10,9,1
7,5,43,0
15,8,13,2
4,15,42,2
6,7,4,0
2,6,46,1
13,12,3,2
7,4,44,0
13,3,38,0
7,9,28,1
7,4,35,1
11,2,29,0
12,15,25,1
13,10,12,1
3,13,41,2
11,10,4,0
14,9,30,1
10,11,17,1
3,11,43,0
9,5,33,0
11,10,14,1
15,13,30,2
7,2,43,1
11,10,46,0
3,10,30,0
3,14,44,0
13,5,16,1
13,10,31,2
2,7,13,1
7,8,38,0
4,9,40,0
11,4,45,1
12,12,46,0
13,14,43,1
8,3,13,2
4,5,13,2
13,14,8,0
11,15,33,2
14,1,31,2
2,15,32,0
8,1,38,2
12,9,22,0
2,8,21,0
8,2,25,1
6,14,32,0
15,12,49,2
6,15,21,1
4,6,2,1
12,1,33,1
11,8,22,2
2,5,48,1
13,6,11,1
8,3,30,2
7,1,26,1
10,4,11,2
8,10,7,2
2,1,41,0
12,4,6,0
11,11,49,1
12,8,7,2
3,13,35,0
8,2,46,1
1,3,22,2
9,9,17,1
15,5,21,0
5,11,15,0
10,3,35,0
5,13,46,2
2,4,43,1
7,3,47,0
5,10,29,0
11,8,45,1
12,12,10,1
14,5,19,2
15,5,24,0
2,4,28,0
2,9,8,0
3,2,20,2
9,7,11,2
5,1,37,1
9,5,39,0
11,10,33,2
6,10,17,0
5,7,12,2
15,9,37,2
1,8,17,2
15,3,8,1
9,8,11,1
8,12,29,0
10,4,10,0
15,13,28,2
13,7,32,0
7,3,47,0
5,8,12,1
11,12,42,2
1,14,28,0
8,5,26,0
2,8,42,1
9,10,33,0
10,1,39,1
7,7,15,2
4,14,36,0
9,11,38,0
8,8,16,1
14,3,22,2
11,11,27,2
1,9,39,1
8,11,49,0
3,6,3,1
12,3,9,0
4,13,10,0
2,8,14,2
10,6,20,1
4,5,6,1
6,10,32,0
2,8,39,0
5,13,31,1
3,3,2,2
7,2,28,2
4,10,29,2
7,14,39,1
14,13,12,2
15,6,23,0
13,9,5,0
3,8,40,0
15,2,28,0
13,9,33,1
3,14,24,1
11,2,9,0
11,13,21,0
2,12,16,0
1,3,26,2
10,15,20,1
15,3,3,1
14,1,36,1
13,10,37,1
1,12,10,2
9,6,45,1
14,11,20,2
14,4,10,1
4,10,38,1
7,15,48,2
12,6,44,2
2,14,48,0
8,10,26,2
1,11,20,2
12,4,24,0
10,2,22,1
14,11,23,0
10,4,22,2
4,12,21,1
7,8,27,0
15,15,37,0
10,8,23,0
7,2,16,2
2,14,3,2
3,10,19,1
9,10,45,2
10,15,22,1
11,3,25,2
15,1,36,0
2,8,49,2
8,5,27,2
5,9,33,0
10,4,6,2
1,10,29,1
6,2,34,0
2,8,3,0
1,13,43,2
13,5,15,1
5,10,28,0
5,15,34,2
5,6,25,2
6,12,10,1
5,5,7,2
5,6,37,1
5,10,40,0
12,2,23,0
13,4,8,1
1,3,21,2
10,4,24,2
9,5,44,1
11,7,35,1
15,10,18,0
2,11,10,0
15,5,43,2
1,3,28,0
12,15,32,0
7,12,20,2
11,7,18,1
13,7,41,0
2,15,17,2
7,15,21,1
14,8,17,1
3,11,44,2
15,7,33,1
8,7,8,0
1,8,28,0
9,7,21,0
13,8,27,2
1,3,50,0
13,1,14,2
8,4,34,2
6,4,31,2
4,6,28,0
9,5,20,2
7,3,15,2
14,6,36,2
10,13,9,1
12,10,47,0
6,6,42,0
12,9,8,1
11,5,5,2
8,13,25,0
14,4,48,0
13,11,40,2
9,9,25,0
1,13,11,1
13,12,14,0
3,3,42,0
1,11,37,0
11,15,17,0
6,5,17,1
13,4,36,0
2,3,6,1
12,6,36,1
2,13,4,1
2,15,49,1
3,11,32,0
10,13,41,1
15,4,38,0
3,5,32,1
2,13,44,2
10,1,38,0
10,7,17,0
3,10,11,2
4,14,21,1
7,13,28,2
11,7,16,1
9,15,43,1
1,12,15,2
15,12,42,0
14,15,49,2
9,8,41,1
4,13,8,2
6,9,41,0
7,8,14,2
10,6,25,0
15,12,9,2
9,14,36,1
14,11,30,0
15,6,19,0
3,10,41,1
11,7,16,2
9,8,41,0
14,11,35,0
13,9,15,1
10,13,2,1
1,12,21,0
13,14,46,1
14,10,5,1
11,11,41,2
9,11,2,0
3,11,28,2
1,7,7,0
11,3,7,0
2,8,41,1
6,8,19,0
1,15,21,2
10,11,26,0
12,10,6,2
8,10,5,2
6,3,4,2
11,5,43,1
3,5,3,2
8,4,50,0
11,15,10,0
12,8,23,2
13,11,26,0
14,13,23,2
15,10,37,1
13,9,21,0
3,11,36,1
13,8,13,0
10,1,36,0
3,9,26,1
14,2,48,0
3,11,32,0
13,9,31,2
1,8,8,1
6,11,37,2
13,11,24,1
13,2,35,2
13,3,25,1
14,7,36,2
1,4,29,0
12,3,22,1
8,8,14,2
9,10,48,0
10,11,40,2
14,1,24,0
11,3,24,2
14,9,21,2
14,6,3,1
11,10,41,2
4,8,7,2
8,2,11,2
4,12,42,0
8,9,10,1
9,14,39,2
10,8,38,0
13,9,40,2
2,15,44,1
1,10,47,2
5,1,34,2
7,14,44,1
6,10,13,1
14,5,43,1
2,10,5,1
13,10,36,0
2,12,42,1
13,11,7,2
8,11,34,0
10,8,49,0
7,14,36,1
5,15,11,1
3,5,46,0
6,8,11,0
5,9,45,2
7,15,24,2
13,1,16,2
12,6,34,2
1,12,40,0
11,1,47,0
8,5,46,1
13,15,4,1
5,7,24,1
15,6,11,0
11,11,37,0
7,3,35,0
13,11,14,1
8,9,20,2
8,7,16,2
6,3,12,0
14,9,19,1
10,4,34,1
3,15,22,0
8,15,21,0
7,10,27,1
7,4,34,0
7,10,2,0
13,8,21,0
12,2,35,2
14,15,24,2
13,8,11,2
9,4,45,2
15,6,37,1
6,10,24,1
8,15,34,2
14,12,43,2
3,6,15,1
11,2,44,0
11,8,39,2
10,9,16,1
13,12,46,2
11,10,12,1
2,5,18,2
2,1,4,0
14,6,19,2
10,9,32,0
3,8,40,0
2,12,41,2
2,8,22,2
4,8,6,1
2,12,33,0
3,2,43,2
14,2,36,0
4,6,20,0
3,3,15,2
6,7,2,0
15,5,16,0
3,3,18,2
13,3,10,2
5,15,49,1
13,4,2,0
14,4,44,0
8,3,5,2
5,3,11,1
15,15,38,1
8,12,28,0
2,13,27,1
15,5,46,0
14,11,12,2
13,9,32,1
2,10,15,2
4,10,34,2
4,10,33,0
12,5,7,2
6,14,28,2
2,3,50,1
10,2,5,2
4,1,29,1
3,9,17,0
8,2,19,2
10,8,23,2
2,14,23,2
10,3,3,1
3,10,30,2
13,9,46,1
15,7,26,1
9,15,16,1
11,4,2,0
9,13,12,0
3,15,2,1
6,11,22,0
10,9,24,1
10,11,17,1
14,7,36,1
8,7,30,1
9,14,37,0
12,2,14,1
15,12,36,1
15,2,45,0
3,6,20,2
8,15,33,0
6,11,6,2
1,13,36,2
14,3,14,1
13,1,9,1
9,11,7,0
14,1,21,1
8,7,12,2
3,5,3,1
14,13,31,1
13,5,31,1
10,5,14,0
15,14,10,0
6,12,8,2
4,3,35,0
5,1,48,1
4,14,28,0
11,10,39,1
14,14,2,0
11,15,18,0
1,9,21,0
12,6,37,0
9,8,27,2
2,12,47,2
5,10,45,2
8,3,17,1
5,3,7,2
3,10,34,2
8,14,39,1
9,6,40,2
15,7,21,2
7,13,8,0
15,6,11,0
13,14,26,0
8,2,35,0
15,11,40,0
10,12,28,2
7,2,29,0
1,13,49,1
10,6,44,2
12,11,17,0
10,7,17,1
8,10,25,0
2,12,35,1
12,14,9,1
12,13,30,1
15,13,43,0
6,8,33,2
10,12,38,0
11,8,38,2
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment