Python Code Kubota
Python Code Kubota
python
CopyEdit
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
Assuming the survey data is in a CSV file (kubota_survey_data.csv), we'll clean missing
values and categorize data.
python
CopyEdit
# Load dataset
df = pd.read_csv("kubota_survey_data.csv")
python
CopyEdit
# Correlation heatmap
plt.figure(figsize=(12,6))
sns.heatmap(df.corr(), annot=True, cmap="coolwarm")
plt.title("Correlation Heatmap of Survey Features")
plt.show()
python
CopyEdit
# Boxplot: Satisfaction Score vs. Brand Loyalty
plt.figure(figsize=(10,5))
sns.boxplot(x=df["Brand_Loyalty"], y=df["Satisfaction_Score"],
palette="Set2")
plt.title("Satisfaction Score vs. Brand Loyalty")
plt.xlabel("Loyalty (1 = Will Buy Again, 0 = Not Sure/No)")
plt.ylabel("Satisfaction Score")
plt.show()
4️⃣ Predictive Modeling: Customer Loyalty Prediction
We'll use Logistic Regression & Random Forest to predict whether a customer will buy a
Kubota tractor again.
Splitting Data
python
CopyEdit
X = df.drop(["Brand_Loyalty"], axis=1) # Independent variables
y = df["Brand_Loyalty"] # Target variable
python
CopyEdit
# Train Logistic Regression Model
log_model = LogisticRegression()
log_model.fit(X_train, y_train)
# Predictions
y_pred_log = log_model.predict(X_test)
# Model Accuracy
print("Logistic Regression Accuracy:", accuracy_score(y_test,
y_pred_log))
print(classification_report(y_test, y_pred_log))
python
CopyEdit
# Train Random Forest Model
rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
rf_model.fit(X_train, y_train)
# Predictions
y_pred_rf = rf_model.predict(X_test)
# Model Accuracy
print("Random Forest Accuracy:", accuracy_score(y_test, y_pred_rf))
print(classification_report(y_test, y_pred_rf))
Expected Outcome: This will predict which factors impact brand loyalty, helping
Kubota optimize its strategies.
Survey design, data collection methods, sample size, and tools used