Commit c70a55e7 authored by isurugunarathna's avatar isurugunarathna

Adding new python Modules and SVM

parent 1e2cbf4c
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CsvFileAttributes">
<option name="attributeMap">
<map>
<entry key="\diet_plan\weight_data.csv">
<value>
<Attribute>
<option name="separator" value="," />
</Attribute>
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
#import pandas
import pandas as pd
#creating columns for dataset preview
col_names = ['breed', 'age', 'weight', 'label']
dog_breeds = ["german_sheppard", "labrador", "pomeranian", "husky", "golden_retriever", "poodle", "bulldog", "shiba", "rottweiler","boxer","Dobermen"]
# reading data set
dog_breeds = ["german_sheppard", "labrador", "pomeranian", "husky", "golden_retriever", "poodle", "bulldog", "shiba", "rottweiler"]
# load dataset
pima = pd.read_csv("weight_data.csv", header=None, names=col_names)
print("===================")
print("Dataset head")
print("===================")
#previewing the head of data set
print(pima.head())
#split dataset in to features and target variable
#split dataset in features and target variable
feature_cols = ['breed', 'age', 'weight']
X = pima[feature_cols] # Features
y = pima.label # Target variable
#Use sklearn to train dataset
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
#use logistic Regression
from sklearn.linear_model import LogisticRegression
# instantiate the model (using the default parameters)
......@@ -32,6 +27,7 @@ logreg = LogisticRegression()
# fit the model with data
logreg.fit(X_train,y_train)
#
y_pred=logreg.predict(X_test)
# import the metrics class
......@@ -40,18 +36,16 @@ cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
print("===================")
print("Confusion matrix")
print("===================")
#printing a confusion matrix
print(cnf_matrix)
print("===================")
print("Accuracy")
print("===================")
#printing the accuracy of model
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([[5,4,22]])
y_prediction_test = logreg.predict([[1,1,3]])
y_labels = ["Overweight", "Normal", "Underweight"]
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