- Machine Learning for Cybersecurity Cookbook
- Emmanuel Tsukerman
- 112字
- 2021-06-24 12:28:58
How to do it...
In the following steps, we will demonstrate how to instantiate, train, and test an XGBoost classifier:
- Start by reading in the data:
import pandas as pd
df = pd.read_csv("file_pe_headers.csv", sep=",")
y = df["Malware"]
X = df.drop(["Name", "Malware"], axis=1).to_numpy()
- Next, train-test-split a dataset:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
- Create one instance of an XGBoost model and train it on the training set:
from xgboost import XGBClassifier
XGB_model_instance = XGBClassifier()
XGB_model_instance.fit(X_train, y_train)
- Finally, assess its performance on the testing set:
from sklearn.metrics import accuracy_score
y_test_pred = XGB_model_instance.predict(X_test)
accuracy = accuracy_score(y_test, y_test_pred)
print("Accuracy: %.2f%%" % (accuracy * 100))
The following screenshot shows the output:

推薦閱讀
- 腦動力:Linux指令速查效率手冊
- 計算機原理
- 網上生活必備
- VMware Performance and Capacity Management(Second Edition)
- 中國戰略性新興產業研究與發展·智能制造
- 自動控制理論(非自動化專業)
- 網絡安全與防護
- Machine Learning with the Elastic Stack
- 運動控制系統
- 電腦日常使用與維護322問
- 寒江獨釣:Windows內核安全編程
- Mastering Predictive Analytics with scikit:learn and TensorFlow
- 穿越計算機的迷霧
- 多傳感器數據智能融合理論與應用
- 數字孿生技術與工程實踐:模型+數據驅動的智能系統