python: logistic regression the odds that a directoe has customer contacr
时间: 2024-05-16 19:12:58 浏览: 92
机器学习算法之使用Python实现LogisticRegression算法.zip
Logistic regression is a statistical method used to predict the probability of a binary outcome (such as yes or no, success or failure) based on one or more input variables. In your case, you want to predict the odds that a director has customer contact.
To apply logistic regression in Python, you can use the scikit-learn library. Here's an example code snippet:
```
import pandas as pd
from sklearn.linear_model import LogisticRegression
# load the data into a pandas dataframe
data = pd.read_csv('customer_contact_data.csv')
# specify the input (X) and output (y) variables
X = data[['age', 'gender', 'income']]
y = data['has_customer_contact']
# create a logistic regression model
model = LogisticRegression()
# fit the model to the data
model.fit(X, y)
# use the model to make predictions on new data
new_data = pd.DataFrame({'age': [35], 'gender': ['male'], 'income': [75000]})
prediction = model.predict(new_data)
# print the predicted probability
print(model.predict_proba(new_data))
```
In this example, we load the data from a CSV file into a pandas dataframe and specify the input variables (age, gender, income) and the output variable (has_customer_contact). We then create a logistic regression model, fit it to the data, and use it to make predictions on new data (in this case, a 35-year-old male earning $75,000 per year). Finally, we print the predicted probability of the director having customer contact.
阅读全文