-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.py
More file actions
31 lines (24 loc) · 899 Bytes
/
train.py
File metadata and controls
31 lines (24 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import joblib
# Load your marketing CSV
df = pd.read_csv("train.csv")
df = pd.read_csv("text.csv")
df = pd.read_csv("bigdata.csv")
# Feature engineering
df["CTR (%)"] = (df["Clicks"] / df["Impressions"]) * 100
df["CPC (₹)"] = df["Spend (₹)"] / df["Clicks"]
df["CPA (₹)"] = df["Spend (₹)"] / df["Conversions"]
features = ["Impressions", "Clicks", "Spend (₹)", "CTR (%)", "CPC (₹)", "CPA (₹)"]
target = "Conversions"
X = df[features]
y = df[target]
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train the model
model = RandomForestRegressor()
model.fit(X_train, y_train)
# Save model
joblib.dump(model, "model.pkl")
print("✅ Model trained and saved as model.pkl")