Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

logistic regression algorithm in python

# 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)
Comment

logistic regression algorithm

# Import the necessary modules
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, classification_report

# Create training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.4, random_state=42)

# Create the classifier: logreg
logreg = LogisticRegression()

# Fit the classifier to the training data
logreg.fit(X_train, y_train)

# Predict the labels of the test set: y_pred
y_pred = logreg.predict(X_test)

# Compute and print the confusion matrix and classification report
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))
Comment

logistic regression algorithm in python

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))
Comment

logistic regression algorithm in python

# import the metrics class
from sklearn import metrics
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
cnf_matrix
Comment

PREVIOUS NEXT
Code Example
Python :: string list to int list python 
Python :: merge keep left index 
Python :: EOFError: EOF when reading a line 
Python :: function wrapper with variable number of arguments python 
Python :: ImportError: cannot import name include 
Python :: obtain files python 
Python :: python3.8 
Python :: numpy reshape (n ) to (n 1) 
Python :: django from 
Python :: del list python 
Python :: numpy evenly spaced numbers 
Python :: To create a SparkSession 
Python :: slicing of strings in python 
Python :: Kivy Python ListView Scrollview with Toggle on off 
Python :: removing duplicates from django models data 
Python :: how to serach for multiple attributes in xpath selenium python 
Python :: change column names pandas 
Python :: loop through list of lists jinja 
Python :: quantile-quantile plot python 
Python :: how to add value in array django 
Python :: for loop with index python 
Python :: condition python 
Python :: python string: .join() 
Python :: how to merge dictionaries in python 
Python :: chr() function in python 
Python :: how to use prettytable in python 
Python :: faker, generates fake data for you 
Python :: python portfolio projects 
Python :: python dataframe appendisnt showing 
Python :: seaborn and matplotlib python 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =