rxPredict.rxDForest-OutData-没有结果

时间:2019-02-25 16:15:36

标签: sql r sql-server

如何将预测结果输出到SQL数据表。 脚本运行,但没有从我的rxPredixt函数中写出表 请参阅下面的代码,查看我的最后一条语句。 class_prediction是否保存可以导出的数据。 我对此很陌生

connStr <- paste("Driver=SQL Server;Server=", "DESKTOP-0I1M5VE", ";Database=" , "RandomForest" , ";Trusted_Connection=true;" , sep="" );

#The query that we are using to select data from SQL Server
input_query <- "Select * from credit";

# Input Product data that needs to be classified. This is the result we get from our query

SQLData <- RxSqlServerData(sqlQuery = input_query,
                           connectionString = connStr);
credit <- rxDataStep(SQLData);
credit<-as.data.frame(unclass(credit));



##  Create Training / Testing datasets

# Total number of rows in the credit data frame
n <- nrow(credit);

# Number of rows for the training set (80% of the dataset)
n_train <- round(0.80 * n);

# Create a vector of indices which is an 80% random sample
set.seed(123);
train_indices <- sample(1:n, n_train);

# Subset the credit data frame to training indices only
credit_train <- credit[train_indices, ];

# Exclude the training indices to create the test set
credit_test <- credit[-train_indices, ];

##  Train a Random Forest model

OutDataFile = RxSqlServerData(table = "RandomForestOut", connectionString = connStr);
# Train a Random Forest
set.seed(1)     # for reproducibility;

credit_model <- rxDForest(formula = default ~ checking_balance +months_loan_duration +credit_history
                          +  purpose    +amount +savings_balance +employment_duration   
                          +percent_of_income   +years_at_residence  +age    +other_credit         
                          +housing  +existing_loans_count   +job +dependents +phone , data = credit_train);

class_prediction <- rxPredict(modelObject = credit_model,        # Random Forest model object 
                              data = credit_test,        # Test dataset
                              outData = OutDataFile, overwrite=TRUE, computeResiduals = TRUE)    ;

0 个答案:

没有答案