Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 sklearn regression to excel
#1
#I'm using the following to generate linear model coefficients
#I'm only showing some of the code here
#They print out OK in the DOS window

import numpy as np
from sklearn.preprocessing import PolynomialFeatures
from sklearn import linear_model
clf  = linear_model.LinearRegression()
print("Coefficients: ", clf.coef_)
#But how can I write the coefficients out to Excel using xlsxwriter...

import xlsxwriter
workbook = xlsxwriter.Workbook('Test.xlsx')
worksheet = workbook.add_worksheet('MySheet')

#code goes here

workbook.close()
#I'm not sure how to do this and been trying for hours
# Trying worksheet.write (row, col, clf.coef_) just throws an error
# Think it might have something to do with it being an array.

I'm a real newbie here so hopelessly lost.
Any help greatly appreciated even if just a suggestion. Thanks
Quote
#2
I figured it out, can just refer to clf.coef_ array elements like this

worksheet.write (row, col, clf.coef[0])
worksheet.write (row, col, clf.coef[1])
worksheet.write (row, col, clf.coef[2])
...
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Error When Using sklearn Predict Function firebird 0 118 Mar-21-2020, 04:34 PM
Last Post: firebird
  Outputing LogisticRegression Coefficients (sklearn) RawlinsCross 6 330 Feb-27-2020, 02:47 PM
Last Post: RawlinsCross
  Predicting an output variable with sklearn Ccross1 1 478 Jun-04-2019, 03:11 PM
Last Post: michalmonday
  sklearn imported but not recognized kerberg 6 8,564 Jun-18-2017, 12:32 PM
Last Post: snippsat
  Sklearn Agglomerative Hierarchical Clustering - help with array set up pstarrett 4 2,279 Feb-21-2017, 05:05 AM
Last Post: pstarrett

Forum Jump:


Users browsing this thread: 1 Guest(s)