I am doing a binary classification, predicted values are 0 and 1, is there is any way to get features values for a prediction value.
for eg: I have 2 features 'Age' and 'Salary' and target value is 'purchased'. Age Salary Purchased 19 19000 0 35 20000 0 27 30000 1 41 29000 1 65 40000 1
So, I want to know for each test case outcome (0 or 1) what were features values (Age and Salary).
import pandas as pd
df = pd.read_csv('data.csv')
x = df.iloc[:,[0,1]]
y = df.iloc[:,2]
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,random_state=0)
from sklearn.linear_model import LogisticRegression
regressor = LogisticRegression()
regressor.fit(x_train,y_train)
y_pred=regressor.predict(x_test)
x_test
has all of your features at the same index as their predictions iny_pred
. Are you looking for a way to combine them into a single data structure? Create a visualization of their relationship?regressor.coef_
orregressor.intercept_