Commit 1b52251e authored by Shalitha Deshan Jayasekara's avatar Shalitha Deshan Jayasekara 🏘

Merge branch 'IT18523256_GunarathnaK.A.G.I.P.T' into 'master'

Adding Comments and dog breeds

See merge request !14
parents 0c71a422 1e2cbf4c
#import pandas #import pandas
import pandas as pd import pandas as pd
#creating columns for dataset preview
col_names = ['breed', 'age', 'weight', 'label'] col_names = ['breed', 'age', 'weight', 'label']
# load dataset dog_breeds = ["german_sheppard", "labrador", "pomeranian", "husky", "golden_retriever", "poodle", "bulldog", "shiba", "rottweiler","boxer","Dobermen"]
# reading data set
pima = pd.read_csv("weight_data.csv", header=None, names=col_names) pima = pd.read_csv("weight_data.csv", header=None, names=col_names)
print("===================") print("===================")
print("Dataset head") print("Dataset head")
print("===================") print("===================")
#previewing the head of data set
print(pima.head()) print(pima.head())
#split dataset in to features and target variable
#split dataset in features and target variable
feature_cols = ['breed', 'age', 'weight'] feature_cols = ['breed', 'age', 'weight']
X = pima[feature_cols] # Features X = pima[feature_cols] # Features
y = pima.label # Target variable y = pima.label # Target variable
#Use sklearn to train dataset
from sklearn.model_selection import train_test_split 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) X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=0)
# import the class # import the class
#use logistic Regression
from sklearn.linear_model import LogisticRegression from sklearn.linear_model import LogisticRegression
# instantiate the model (using the default parameters) # instantiate the model (using the default parameters)
...@@ -26,7 +32,6 @@ logreg = LogisticRegression() ...@@ -26,7 +32,6 @@ logreg = LogisticRegression()
# fit the model with data # fit the model with data
logreg.fit(X_train,y_train) logreg.fit(X_train,y_train)
#
y_pred=logreg.predict(X_test) y_pred=logreg.predict(X_test)
# import the metrics class # import the metrics class
...@@ -35,16 +40,18 @@ cnf_matrix = metrics.confusion_matrix(y_test, y_pred) ...@@ -35,16 +40,18 @@ cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
print("===================") print("===================")
print("Confusion matrix") print("Confusion matrix")
print("===================") print("===================")
#printing a confusion matrix
print(cnf_matrix) print(cnf_matrix)
print("===================") print("===================")
print("Accuracy") print("Accuracy")
print("===================") print("===================")
#printing the accuracy of model
print("Accuracy:",metrics.accuracy_score(y_test, y_pred)) print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
# print("Precision:",metrics.precision_score(y_test, y_pred)) # print("Precision:",metrics.precision_score(y_test, y_pred))
# print("Recall:",metrics.recall_score(y_test, y_pred)) # print("Recall:",metrics.recall_score(y_test, y_pred))
# Prediction test # Prediction test
y_prediction_test = logreg.predict([[12,3,48]]) y_prediction_test = logreg.predict([[5,4,22]])
y_labels = ["Overweight", "Normal", "Underweight"] y_labels = ["Overweight", "Normal", "Underweight"]
print(y_labels[y_prediction_test[0]]) print(y_labels[y_prediction_test[0]])
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