Created
June 19, 2022 10:21
-
-
Save charlie2951/0ea487eb50e2ee60feaa0599c3eb46b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
col_names = ['pregnant', 'glucose', 'bp', 'skin', 'insulin', 'bmi', 'pedigree', 'age', 'label'] | |
# load dataset | |
pima = pd.read_csv("diabetes.csv") | |
pima.head() | |
#split dataset in features and target variable | |
feature_cols = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness','Insulin','BMI','DiabetesPedigreeFunction', 'Age'] | |
Xraw = pima[feature_cols] # Features | |
y = pima.Outcome # Target variable | |
from sklearn.preprocessing import StandardScaler | |
scaler = StandardScaler() | |
X = scaler.fit_transform(Xraw) | |
# split X and y into training and testing sets | |
from sklearn.model_selection import train_test_split | |
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.13,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) | |
cnf_matrix | |
"""**Print Weight and bias vectors**""" | |
print('Weight matrix:') | |
print(logreg.coef_) # returns a matrix of weights (coefficients) | |
import numpy as np | |
print('Bias value:') | |
np.hstack(logreg.intercept_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment