向量化代码:
vectorizer = CountVectorizer(ngram_range=(2, 5),
token_pattern=r'\w',
decode_error='ignore',
strip_accents='ascii',
max_features=10000,
stop_words='english',
max_df=1.0,
min_df=1)
x = vectorizer.transform(alexa + dga)
1.朴素贝叶斯
模型训练代码:
from sklearn.naive_bayes import GaussianNB
gbn = GaussianNB()
gbn.fit(x, y)
2.Xgboost:
import xgboost as xgb
import xgboost as xgb
xgb_model = xgb.XGBClassifier().fit(x, y)
3.MLP:
from sklearn.neural_network import MLPClassifier
mlp = MLPClassifier(solver='lbfgs',
alpha=1e-5,
hidden_layer_sizes=(5, 2),
random_state=1)
mlp.fit(x, y)
网友评论