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]])
This diff is collapsed.
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