-
Notifications
You must be signed in to change notification settings - Fork 27
fix(ctr): add a logistic regression ctr ml model. #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.linear_model import LogisticRegression | ||
from sklearn.metrics import accuracy_score, roc_auc_score | ||
|
||
# 创建虚拟数据 | ||
data = pd.DataFrame({ | ||
'feature1': np.random.rand(1000), | ||
'feature2': np.random.rand(1000), | ||
'feature3': np.random.rand(1000), | ||
'clicked': np.random.randint(0, 2, 1000) | ||
}) | ||
|
||
# 定义特征和目标变量 | ||
X = data[['feature1', 'feature2', 'feature3']] | ||
y = data['clicked'] | ||
|
||
# 将数据分为训练集和测试集 | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | ||
|
||
# 创建逻辑回归模型 | ||
log_reg = LogisticRegression() | ||
|
||
# 训练模型 | ||
log_reg.fit(X_train, y_train) | ||
|
||
# 预测测试集 | ||
y_pred = log_reg.predict(X_test) | ||
y_pred_proba = log_reg.predict_proba(X_test)[:, 1] | ||
|
||
# 计算准确率和AUC | ||
accuracy = accuracy_score(y_test, y_pred) | ||
auc = roc_auc_score(y_test, y_pred_proba) | ||
|
||
print("Accuracy: ", accuracy) | ||
print("AUC: ", auc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not recommended to add this code to the model folder. The model folder should only contain the basic definitions of the model, and this code should be re-organized and placed as a demo in the quick start