Logistic Regression in Python – Step 4.) Training the Logistic Regression Model

with No Comments

#Import Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#Import Dataset
dataset = pd.read_csv(‘Social_Network_Ads.csv’)
x = dataset.iloc[:,[2,3]].values
y =dataset.iloc[:,4].values

#Split Training Set and Testing Set
from sklearn.cross_validation import train_test_split
x_train, x_test, y_train, y_test =train_test_split(x,y,test_size=0.25)

#Feature Scaling
from sklearn.preprocessing import StandardScaler

#Training the Logistic Model
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression()
classifier.fit(x_train, y_train)



Leave a Reply