Usage
microsoftml.concat(cols: [dict, list], **kargs)
설명
여러 열을 하나의 벡터 값 열로 결합합니다.
세부 정보
concat 여러 열을 조합해 단일 벡터 값 열을 생성합니다. 이 작업은 모델을 학습하기 전에 데이터에 대해 수행할 수 있습니다. 열 수가 수백에서 수천 개에 이르는 경우, 이 연결 방식은 데이터 처리 속도를 크게 높일 수 있습니다.
Arguments
cols
변환할 변수 이름 목록이나 캐릭터 dict. 만약 이면 dict, 키는 새로 생성할 변수들의 이름을 나타냅니다.
모든 입력 변수는 반드시 같은 타입이어야 한다는 점에 유의하세요. 연결 변환을 통해 여러 출력 열을 생성할 수 있습니다. 이 경우에는 벡터 목록을 사용해 입력과 출력 변수 간의 일대일 매핑을 정의해야 합니다.
예를 들어, InNameA 및 InNameB 열을 OutName1 열로, InNameC 및 InNameD 열을 OutName2 열로 연결하려면 dict(OutName1 = [InNameA, InNameB], outName2 = [InNameC, InNameD])
kargs
추가 인수들이 컴퓨트 엔진에 전송됩니다.
Returns
연결 변환을 정의하는 객체입니다.
Example
'''
Example on logistic regression and concat.
'''
import numpy
import pandas
import sklearn
from microsoftml import rx_logistic_regression, concat, rx_predict
from microsoftml.datasets.datasets import get_dataset
iris = get_dataset("iris")
if sklearn.__version__ < "0.18":
from sklearn.cross_validation import train_test_split
else:
from sklearn.model_selection import train_test_split
# We use iris dataset.
irisdf = iris.as_df()
# The training features.
features = ["Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width"]
# The label.
label = "Label"
# microsoftml needs a single dataframe with features and label.
cols = features + [label]
# We split into train/test. y_train, y_test are not used.
data_train, data_test, y_train, y_test = train_test_split(irisdf[cols], irisdf[label])
# We train a logistic regression.
# A concat transform is added to group features in a single vector column.
multi_logit_out = rx_logistic_regression(
formula="Label ~ Features",
method="multiClass",
data=data_train,
ml_transforms=[concat(cols={'Features': features})])
# We show the coefficients.
print(multi_logit_out.coef_)
# We predict.
prediction = rx_predict(multi_logit_out, data=data_test)
print(prediction.head())
Output:
Automatically adding a MinMax normalization transform, use 'norm=Warn' or 'norm=No' to turn this behavior off.
Beginning processing data.
Rows Read: 112, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 112, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 112, Read Time: 0.001, Transform Time: 0
Beginning processing data.
LBFGS multi-threading will attempt to load dataset into memory. In case of out-of-memory issues, turn off multi-threading by setting trainThreads to 1.
Beginning optimization
num vars: 15
improvement criterion: Mean Improvement
L1 regularization selected 9 of 15 weights.
Not training a calibrator because it is not needed.
Elapsed time: 00:00:00.2348578
Elapsed time: 00:00:00.0197433
OrderedDict([('0+(Bias)', 1.943994402885437), ('1+(Bias)', 0.6346845030784607), ('2+(Bias)', -2.57867693901062), ('0+Petal_Width', -2.7277402877807617), ('0+Petal_Length', -2.5394322872161865), ('0+Sepal_Width', 0.4810805320739746), ('1+Sepal_Width', -0.5790582299232483), ('2+Petal_Width', 2.547518491744995), ('2+Petal_Length', 1.6753791570663452)])
Beginning processing data.
Rows Read: 38, Read Time: 0, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.0662932
Finished writing 38 rows.
Writing completed.
Score.0 Score.1 Score.2
0 0.320061 0.504115 0.175825
1 0.761624 0.216213 0.022163
2 0.754765 0.215548 0.029687
3 0.182810 0.517855 0.299335
4 0.018770 0.290014 0.691216