我已经下载了心脏病数据库。但是,某些值,例如"restecg"
和"cp"
具有多个可能的值。我想将这些值分为值0或1的自己的列,然后对它们执行逻辑回归。通常,在python中,我会这样做
import pandas as pd
import numpy as np
from sklearn import preprocessing
from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import train_test_split
data = pd.read_csv('bank.csv', header = 0)
data = data.dropna()
dataRefactored = pd.get_dummies(data, columns=['...']) #Collumns I want to get dummies for
X_train, X_test, Y_train, Y_test = train_test_split(X, Y)
classifier = LogisticRegression()
classifier.fit(X_train, Y_train)
如果输入是:
Slope
1
3
2
1
输出为:
Slope_1 Slope_2 Slope_3
1 0 0
0 0 1
0 1 0
1 0 0
我该如何在JS中复制它?