Python Forum
Predicting an output variable with sklearn
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Predicting an output variable with sklearn
#1
*Disclaimer: I am new to this forum so I apologize if I am posting this in a way that does not conform to the best practices. This is a relatively general question but I appreciate any help that is subsequently provided.*

I am new to python and I am not sure how to accomplish my objective.

I have a relatively small data set that I was given for research to fit a model that will accurately predict a continuous value based on two continuous inputs. It does not seem to be a complicated task, but I am unsure how to proceed.

I attempted to run a LinearRegression model but found that this is better suited for categorical data. This is the head from my data set to give you an idea of the type of data that I am attempting to process.

[Image: open?id=1HP4mWEBCpbgBXHSvP2IThj4T9DRWDbzW]
Thanks in advance for any advice / help going forward.

import pandas as pd
LSdata=pd.read_excel('/Users/connercross/Desktop/LSTimePredict.xlsx')
LSdata.head()
Thickness	Length	L S Time
0	0.25	30	1.0
1	0.25	60	1.0
2	0.25	66	1.0
3	0.25	72	1.0
4	0.25	84	1.5
from sklearn.model_selection import train_test_split
x_vars=LSdata.drop('L S Time', axis=1)
y_var=LSdata['L S Time']
xTrain,xValid,yTrain,yValid=train_test_split(x_vars, y_var, train_size=.6, random_state=2)
/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py:2179: FutureWarning: From version 0.21, test_size will always complement train_size unless both are specified.
  FutureWarning)
from sklearn.linear_model import LogisticRegression
logmod=LogisticRegression()
logmod.fit(xTrain, yTrain)
/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-2c6782c908b0> in <module>
----> 1 logmod.fit(xTrain, yTrain)

/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
   1284         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
   1285                          accept_large_sparse=solver != 'liblinear')
-> 1286         check_classification_targets(y)
   1287         self.classes_ = np.unique(y)
   1288         n_samples, n_features = X.shape

/anaconda3/lib/python3.7/site-packages/sklearn/utils/multiclass.py in check_classification_targets(y)
    169     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
    170                       'multilabel-indicator', 'multilabel-sequences']:
--> 171         raise ValueError("Unknown label type: %r" % y_type)
    172 
    173 

ValueError: Unknown label type: 'continuous'
Reply
#2
Hi, could you upload the excel file please?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Column Transformer with Mixed Types - sklearn aaldb 0 250 Feb-22-2024, 03:27 PM
Last Post: aaldb
  sklearn.neural_network MLPClassifier forecast variances CK1960 1 1,780 Oct-29-2020, 10:13 AM
Last Post: CK1960
  Predicting/Forecasting Future Values BadWhite 1 2,320 Jun-15-2020, 11:30 AM
Last Post: hussainmujtaba
  Customizing an sklearn submodule with cython JHogg11 0 1,931 May-27-2020, 05:39 PM
Last Post: JHogg11
  sklearn and train_test_split nsadams87xx 1 1,794 Apr-23-2020, 05:32 PM
Last Post: jefsummers
  Error When Using sklearn Predict Function firebird 0 2,027 Mar-21-2020, 04:34 PM
Last Post: firebird
  Outputing LogisticRegression Coefficients (sklearn) RawlinsCross 6 4,661 Feb-27-2020, 02:47 PM
Last Post: RawlinsCross
  parse json output to simple text or variable murali_datascience 1 2,390 Jun-25-2019, 02:56 PM
Last Post: perfringo
  predicting values at point in time mk1216 1 1,843 May-07-2019, 03:25 PM
Last Post: mk1216
  sklearn regression to excel punksnotdead 1 2,724 Apr-14-2019, 12:32 PM
Last Post: punksnotdead

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020