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

importing logistic regression

sklearn.linear_model.LogisticRegression
Comment

PREVIOUS NEXT
Code Example
Python :: choromap = go.Figure(data=[data], layout = layout) 
Python :: how to read excel with multiple pages on pandas 
Python :: python requests post 
Python :: failed to allocate bitmap 
Python :: randomly choose between two numbers python 
Python :: opencv dilate 
Python :: pandas row from dict 
Python :: jaccard distance python 
Python :: django login_required decorator 
Python :: python get latest edited file from any directory 
Python :: python convert a string to a list of words 
Python :: how to iterate over rows in a dataframe in pandas 
Python :: copy from folder to folder python 
Python :: how to make label background transparent in tkinter 
Python :: print list in reverse order python 
Python :: convert float to integer pandas 
Python :: pyspark split dataframe by rows 
Python :: hello world in python 
Python :: mediafileupload python example 
Python :: wget command python 
Python :: perimeter of circle 
Python :: pygame.rect 
Python :: random number pythob 
Python :: python convert string to sentence case 
Python :: jupyter markdown new line 
Python :: pandas count rows in column 
Python :: numpy matrix power 
Python :: tkinter widget span multiple colums 
Python :: colorbar min max matplotlib 
Python :: python split list into n sublists 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =