저는 Microsoft의 "Data Science End to End Walkthrough"을 사용하여 R 서버로 설정하고 예제를 완벽하게 작동시킵니다.RevoScaleR : rxPredict, 매개 변수의 수가 변수의 수와 일치하지 않습니다.
예제 (뉴욕 택시 데이터)는 카테고리 변수 (팁 지불 여부에 대한 1 또는 0)를 예측하기 위해 비 카테고리 변수 (예 : 거리, 택시 요금 등)를 사용합니다.
선형 회귀 (rxLinMod 함수)를 사용하여 범주 형 변수를 입력으로 사용하여 유사한 이진 출력을 예측하려고합니다. 오류가 발생합니다.
오류는 매개 변수 수가 변수 수와 일치하지 않지만 실제로는 number of variables
이 각 요소 (변수) 내의 수준 수인 것처럼 보입니다. 거기에
USE [my_database];
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
CREATE TABLE [dbo].[example](
[Person] [nvarchar](max) NULL,
[City] [nvarchar](max) NULL,
[Bin] [integer] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];
넣고 데이터 :
insert into [dbo].[example] values ('John','London',0);
insert into [dbo].[example] values ('Paul','New York',0);
insert into [dbo].[example] values ('George','Liverpool',1);
insert into [dbo].[example] values ('Ringo','Paris',1);
insert into [dbo].[example] values ('John','Sydney',1);
insert into [dbo].[example] values ('Paul','Mexico City',1);
insert into [dbo].[example] values ('George','London',1);
insert into [dbo].[example] values ('Ringo','New York',1);
insert into [dbo].[example] values ('John','Liverpool',1);
insert into [dbo].[example] values ('Paul','Paris',0);
insert into [dbo].[example] values ('George','Sydney',0);
insert into [dbo].[example] values ('Ringo','Mexico City',0);
가 나는 또한 변수를 반환하는 SQL 함수를 사용
는
는 SQL Server의 예를라는 테이블을 만들고 복제하려면 테이블 형식으로, Microsoft 예제 에서처럼 필요합니다. - Person
및 City
USE [my_database];
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
CREATE FUNCTION [dbo].[formatAsTable] (
@City nvarchar(max)='',
@Person nvarchar(max)='')
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT
@City AS City,
@Person AS Person
);
우리는 이제 두 개의 범주 변수 테이블이 : 함수 formatAsTable
을 만듭니다.
예측을 시작해 보겠습니다. R에서 다음을 실행하십시오.
library(RevoScaleR)
# Set up the database connection
connStr <- "Driver=SQL Server;Server=<servername>;Database=<dbname>;Uid=<uid>;Pwd=<password>"
sqlShareDir <- paste("C:\\AllShare\\",Sys.getenv("USERNAME"),sep="")
sqlWait <- TRUE
sqlConsoleOutput <- FALSE
cc <- RxInSqlServer(connectionString = connStr, shareDir = sqlShareDir,
wait = sqlWait, consoleOutput = sqlConsoleOutput)
rxSetComputeContext(cc)
# Set the SQL which gets our data base
sampleDataQuery <- "SELECT * from [dbo].[example] "
# Set up the data source
inDataSource <- RxSqlServerData(sqlQuery = sampleDataQuery, connectionString = connStr,
colClasses = c(City = "factor",Bin="logical",Person="factor"
),
rowsPerRead=500)
이제 선형 회귀 모델을 설정하십시오. 그것은 다음과 같습니다
isWonObj
주의 사항 : 모델 객체에서
isWonObj <- rxLinMod(Bin ~ City+Person,data = inDataSource)
봐는
...
Total independent variables: 11 (Including number dropped: 3)
...
Coefficients:
Bin
(Intercept) 6.666667e-01
City=London -1.666667e-01
City=New York 4.450074e-16
City=Liverpool 3.333333e-01
City=Paris 4.720871e-16
City=Sydney -1.666667e-01
City=Mexico City Dropped
Person=John -1.489756e-16
Person=Paul -3.333333e-01
Person=George Dropped
Person=Ringo Dropped
이것이의 합으로 괜찮 11 개 변수,가 말한다 요인의 수준. 내가 City
및 Person
에 따라 Bin
값을 예측하려고 할 때
지금, 오류가 발생합니다 :
먼저 나는 테이블로에 대한 예측 할 City
및 Person
포맷합니다. 그런 다음 이것을 입력으로 사용하는 것이 좋습니다. 당신이 pred
객체를 선택하면
sq<-"SELECT City, Person FROM [dbo].[formatAsTable]('London','George')"
pred<-RxSqlServerData(sqlQuery = sq,connectionString = connStr
, colClasses = c(City = "factor",Person="factor"))
, 그것은 예상대로 보이는 : 나는 예측하려고 할 때
> head(pred)
City Person
1 London George
지금, 나는 오류가 발생합니다.11이 어디에서 오는지
이
INTERNAL ERROR: In rxPredict, the number of parameters does not match the number of variables: 3 vs. 11.
내가 볼 수 있지만 난 단지 예측 쿼리에이 개 값을 제공 한 - 3 어디에서 오는지 그래서 내가 볼 수 없습니다
scoredOutput <- RxSqlServerData(
connectionString = connStr,
table = "binaryOutput"
)
rxPredict(modelObject = isWonObj, data = pred, outData = scoredOutput,
predVarNames = "Score", type = "response", writeModelVars = FALSE, overwrite = TRUE,checkFactorLevels = FALSE)
오류는 말한다 , 또는 문제가있는 이유.
도움을 주시면 감사하겠습니다.
본인의 원래 답변을 편집하여 문제를 통합했습니다. 올바르게 이해하면 도움이됩니다. –