microsoftml.rx_predict: Microsoft 머신러닝 모델을 사용한 점수

Usage

microsoftml.rx_predict(model,
    data: typing.Union[revoscalepy.datasource.RxDataSource.RxDataSource,
    pandas.core.frame.DataFrame],
    output_data: typing.Union[revoscalepy.datasource.RxDataSource.RxDataSource,
    str] = None, write_model_vars: bool = False,
    extra_vars_to_write: list = None, suffix: str = None,
    overwrite: bool = False, data_threads: int = None,
    blocks_per_read: int = None, report_progress: int = None,
    verbose: int = 1,
    compute_context: revoscalepy.computecontext.RxComputeContext.RxComputeContext = None,
    **kargs)

설명

인스턴스별 점수 평가는 학습된 Microsoft ML Machine Learning 모델을 사용하여 arevoscalepydata 소스를 사용하여 데이터 프레임 또는 revoscalepy 데이터 소스를 생성합니다.

세부 정보

기본적으로 출력에 보고되는 항목은 다음과 같습니다: 이진 분류기의 세 변수에 대한 점수 부여: 예측 라벨, 점수, 확률; oneClassSvm 및 회귀분류기 점수; 다중 클래스 분류기에는 PredictedLabel이 추가되며, 각 범주별 변수는 Score 앞에 붙어 있습니다.

Arguments

model

MicrosoftML 모델에서 반환된 모델 정보 객체입니다. 예를 들어, 또는 rx_logistic_regression에서 rx_fast_trees 반환된 객체가 있습니다.

data

revoscalepy 데이터 소스 객체, 데이터 프레임, 또는 파일로 가는 .xdf 경로 등이 있습니다.

output_data

변환된 데이터를 저장할 수 있는 출력 텍스트 또는 xdf 파일 이름 또는 RxDataSource 쓰기 기능을 제공합니다. 으면 데이터 프레임이 반환됩니다. 기본 값은 None입니다.

write_model_vars

만약 이면 True, 모델 내 변수들은 점수 변수 외에도 출력 데이터 세트에 기록됩니다. 입력 데이터 세트의 변수가 모델에서 변환된다면, 변환된 변수들도 포함됩니다. 기본값은 False입니다.

extra_vars_to_write

None또는 입력 데이터에서 추가로 포함된 변수 이름의 문자 벡터를 포함할 수 있습니다.output_data 만약 가 이라Truewrite_model_vars, 모델 변수도 포함됩니다. 기본값은 None입니다.

suffix

생성된 점수 변수에 접미사를 붙이는 문자 문자열 또는 None 그 안에 접미사가 없는 경우. 기본값은 None입니다.

덮어쓸

만약 True, 존재 output_data 하는 것이 덮어쓰여진다면; 존재 output_data 하는 것이 덮어쓰여지지 않았다 False 면. 기본값은 False입니다.

data_threads

데이터 파이프라인에서 원하는 병렬성 정도를 지정하는 정수. 으면 내부적으로 사용되는 스레드 수가 결정됩니다. 기본 값은 None입니다.

blocks_per_read

데이터 원본에서 읽은 데이터의 각 청크에 대해 읽을 블록 수를 지정합니다.

report_progress

행 처리 진행률에 대한 보고 수준을 지정하는 정수 값입니다.

  • 0: 진행률이 보고되지 않습니다.

  • 1: 처리된 행 수가 인쇄되고 업데이트됩니다.

  • 2: 행이 처리되고 타이밍이 보고됩니다.

  • 3: 행이 처리되고 모든 타이밍이 보고됩니다.

기본값은 1입니다.

verbose

원하는 출력의 양을 지정하는 정수 값입니다. 이 경우 0계산 중에 자세한 정보 출력이 인쇄되지 않습니다. 증가하는 양의 정보를 제공하기 위한 1 정수 값 4 입니다. 기본값은 1입니다.

compute_context

계산이 실행되고 유효한 revoscalepy로 지정된 컨텍스트를 설정합니다. RxComputeContext. 현재 로컬 및 revoscalepy입니다. RxInSqlServer 컴퓨팅 컨텍스트가 지원됩니다.

kargs

컴퓨팅 엔진으로 전송된 추가 인수입니다.

Returns

데이터 프레임이나 레보스케일피. 생성된 출력 데이터를 나타내는 RxDataSource 객체입니다. 기본적으로 점수 매기기 이진 분류기의 출력은 세 변수를 포함합니다: PredictedLabel, Score, ; rx_oneclass_svmProbability회귀는 하나의 변수를 포함합니다: Score; 그리고 다중 클래스 분류기는 PredictedLabel 각 범주에 대해 변수를 추가하여 , 로 앞에 붙습니다.Score a가 제공되면 suffix 이 출력 변수 이름 끝에 추가됩니다.

이진 분류 예제

'''
Binary Classification.
'''
import numpy
import pandas
from microsoftml import rx_fast_linear, rx_predict
from revoscalepy.etl.RxDataStep import rx_data_step
from microsoftml.datasets.datasets import get_dataset

infert = get_dataset("infert")

import sklearn
if sklearn.__version__ < "0.18":
    from sklearn.cross_validation import train_test_split
else:
    from sklearn.model_selection import train_test_split

infertdf = infert.as_df()
infertdf["isCase"] = infertdf.case == 1
data_train, data_test, y_train, y_test = train_test_split(infertdf, infertdf.isCase)

forest_model = rx_fast_linear(
    formula=" isCase ~ age + parity + education + spontaneous + induced ",
    data=data_train)
    
# RuntimeError: The type (RxTextData) for file is not supported.
score_ds = rx_predict(forest_model, data=data_test,
                     extra_vars_to_write=["isCase", "Score"])
                     
# Print the first five rows
print(rx_data_step(score_ds, number_rows_read=5))

Output:

Automatically adding a MinMax normalization transform, use 'norm=Warn' or 'norm=No' to turn this behavior off.
Beginning processing data.
Rows Read: 186, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 186, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 186, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Using 2 threads to train.
Automatically choosing a check frequency of 2.
Auto-tuning parameters: maxIterations = 8064.
Auto-tuning parameters: L2 = 2.666837E-05.
Auto-tuning parameters: L1Threshold (L1/L2) = 0.
Using best model from iteration 590.
Not training a calibrator because it is not needed.
Elapsed time: 00:00:00.6058289
Elapsed time: 00:00:00.0084728
Beginning processing data.
Rows Read: 62, Read Time: 0, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.0302359
Finished writing 62 rows.
Writing completed.
Rows Read: 5, Total Rows Processed: 5, Total Chunk Time: 0.001 seconds 
  isCase PredictedLabel     Score  Probability
0  False           True  0.576775     0.640325
1  False          False -2.929549     0.050712
2   True          False -2.370090     0.085482
3  False          False -1.700105     0.154452
4  False          False -0.110981     0.472283

회귀 예제

'''
Regression.
'''
import numpy
import pandas
from microsoftml import rx_fast_trees, rx_predict
from revoscalepy.etl.RxDataStep import rx_data_step
from microsoftml.datasets.datasets import get_dataset

airquality = get_dataset("airquality")

import sklearn
if sklearn.__version__ < "0.18":
    from sklearn.cross_validation import train_test_split
else:
    from sklearn.model_selection import train_test_split

airquality = airquality.as_df()


######################################################################
# Estimate a regression fast forest
# Use the built-in data set 'airquality' to create test and train data

df = airquality[airquality.Ozone.notnull()]
df["Ozone"] = df.Ozone.astype(float)

data_train, data_test, y_train, y_test = train_test_split(df, df.Ozone)

airFormula = " Ozone ~ Solar_R + Wind + Temp "

# Regression Fast Forest for train data
ff_reg = rx_fast_trees(airFormula, method="regression", data=data_train)

# Put score and model variables in data frame
score_df = rx_predict(ff_reg, data=data_test, write_model_vars=True)
print(score_df.head())

# Plot actual versus predicted values with smoothed line
# Supported in the next version.
# rx_line_plot(" Score ~ Ozone ", type=["p", "smooth"], data=score_df)

Output:

'unbalanced_sets' ignored for method 'regression'
Not adding a normalizer.
Making per-feature arrays
Changing data from row-wise to column-wise
Beginning processing data.
Rows Read: 87, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Warning: Skipped 4 instances with missing features during training
Processed 83 instances
Binning and forming Feature objects
Reserved memory for tree learner: 22620 bytes
Starting to train ...
Not training a calibrator because it is not needed.
Elapsed time: 00:00:00.0390764
Elapsed time: 00:00:00.0080750
Beginning processing data.
Rows Read: 29, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.0221875
Finished writing 29 rows.
Writing completed.
   Solar_R  Wind  Temp      Score
0    290.0   9.2  66.0  33.195541
1    259.0  15.5  77.0  20.906796
2    276.0   5.1  88.0  76.594643
3    139.0  10.3  81.0  31.668842
4    236.0  14.9  81.0  43.590839