python - Predict test data using model based on training data set? -
im new data science , analysis. after going through lot of kernels on kaggle, made model predicts price of property. ive tested model using training data, want run on test data. ive got test.csv file , want use it. how do that? did training dataset:
#loading train dataset python train = pd.read_csv('/users/sohaib/downloads/test.csv') #factors predict price train_pr = ['overallqual','grlivarea','garagecars','totalbsmtsf','fullbath','yearbuilt'] #set model decisiontree model = decisiontreeregressor() #set prediction data factors predict, , set target saleprice prdata = train[train_pr] target = train.saleprice #fitting model prediction data , telling target model.fit(prdata, target) model.predict(prdata.head())
now tried is, copy whole code, , change "train" "test", , "predate" "testprdata", , thought work, sadly no. know i'm doing wrong this, idk is.
as long process train , test data same way, predict
function work on either data set. you'll want load both train , test sets, fit
on train, , predict
on either test or both train , test.
also, note file you're reading test
data. assuming file named properly, though named variable train
, training on test data.
#loading train dataset python train = pd.read_csv('/users/sohaib/downloads/train.csv') test = pd.read_csv('/users/sohaib/downloads/test.csv') #factors predict price desired_factors = ['overallqual','grlivarea','garagecars','totalbsmtsf','fullbath','yearbuilt'] #set model decisiontree model = decisiontreeregressor() #set prediction data factors predict, , set target saleprice train_data = train[desired_factors] test_data = test[desired_factors] target = train.saleprice #fitting model prediction data , telling target model.fit(train_data, target) model.predict(test_data.head())
Comments
Post a Comment