{"paragraphs":[{"text":"import matplotlib.pyplot as plt\nfrom sklearn import linear_model\nimport numpy as np\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn import preprocessing\n\ndef newsample(xTest, ytest, model):\n ar = np.array([[[1],[2],[3]], [[2],[4],[6]]])\n y = ar[1,:]\n x = ar[0,:]\n\n if model == 1:\n reg = linear_model.LinearRegression()\n reg.fit(x,y)\n print('least square Coefficients: \\n', reg.coef_)\n if model == 2:\n reg = linear_model.Ridge (alpha = 1)\n reg.fit(x,y)\n print('ridged Coefficients: \\n', ridge.coef_)\n \n preds = reg.predict(xTest)\n\n er = []\n for i in range(len(ytest)):\n print( \"actual=\", ytest[i], \" preds=\", preds[i])\n x = (ytest[i] - preds[i]) **2\n er.append(x)\n\n v = np.var(er)\n print (\"variance\", v)\n \n print(\"Mean squared error (bias): %.2f\" % mean_squared_error(ytest,preds))\n\n tst = preprocessing.scale(ytest)\n prd = preprocessing.scale(preds)\n plt.plot(tst, prd, 'g^')\n \n x1 = preprocessing.scale(xTest)\n fx = preprocessing.scale(xTest * reg.coef_)\n\n plt.plot(x1,fx )\n plt.show()\n\n\na = np.array([[4],[5],[6]])\nb = np.array([[8.8],[14],[17]])\nnewsample(a,b, 1)\n\n","user":"admin","dateUpdated":"2018-07-05T13:10:44+0100","config":{"colWidth":12,"enabled":true,"results":{},"editorSetting":{"language":"python","editOnDblClick":false},"editorMode":"ace/mode/python"},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1529322457628_-1366321680","id":"20180618-124737_619813385","dateCreated":"2018-06-18T12:47:37+0100","dateStarted":"2018-07-05T13:10:44+0100","dateFinished":"2018-07-05T13:10:45+0100","status":"FINISHED","progressUpdateIntervalMs":500,"focus":true,"$$hashKey":"object:635","results":{"code":"SUCCESS","msg":[{"type":"TEXT","data":"least square Coefficients: \n [[2.]]\nactual= [8.8] preds= [8.]\nactual= [14.] preds= [10.]\nactual= [17.] preds= [12.]\nvariance 101.14880000000011\nMean squared error (bias): 13.88\n"},{"type":"HTML","data":"
\n"}]}},{"text":"newsample(a,b, 2)\n","user":"admin","dateUpdated":"2018-07-05T13:10:58+0100","config":{"colWidth":12,"enabled":true,"results":{},"editorSetting":{"language":"python","editOnDblClick":false},"editorMode":"ace/mode/python"},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1529326294404_-1563210258","id":"20180618-135134_904293828","dateCreated":"2018-06-18T13:51:34+0100","dateStarted":"2018-07-05T13:10:58+0100","dateFinished":"2018-07-05T13:10:58+0100","status":"FINISHED","progressUpdateIntervalMs":500,"$$hashKey":"object:636","results":{"code":"SUCCESS","msg":[{"type":"TEXT","data":"ridged Coefficients: \n [[1.6]]\nactual= [8.8] preds= [6.66666667]\nactual= [14.] preds= [8.]\nactual= [17.] preds= [9.33333333]\nvariance 494.2656834019206\nMean squared error (bias): 33.11\n"},{"type":"HTML","data":"
\n"}]}},{"user":"admin","dateUpdated":"2018-07-05T12:53:24+0100","config":{"colWidth":12,"enabled":true,"results":{},"editorSetting":{"language":"python","editOnDblClick":false},"editorMode":"ace/mode/python"},"settings":{"params":{},"forms":{}},"apps":[],"jobName":"paragraph_1530783012788_312908554","id":"20180705-103012_603502398","dateCreated":"2018-07-05T10:30:12+0100","status":"READY","errorMessage":"","progressUpdateIntervalMs":500,"$$hashKey":"object:637"}],"name":"python","id":"2DJKNH4SJ","angularObjects":{"2DFG1UCC9:shared_process":[],"2DJBSJJTG:shared_process":[],"2DFPUNNXY:shared_process":[],"2DFWS92Y9:shared_process":[],"2DH5VBP1N:shared_process":[],"2DHJ15Q9Z:shared_process":[],"2DHDJYQ7M:shared_process":[],"2DK4FSTUG:shared_process":[],"2DHUEP7VA:shared_process":[],"2DHGSHFKW:shared_process":[],"2DGQ75AVT:shared_process":[],"2DGE2M11R:shared_process":[],"2DHKM6QSJ:shared_process":[],"2DHZ6ZNQP:shared_process":[],"2DJEVM7B8:shared_process":[],"2DHJZVV4E:shared_process":[],"2DJ5EUS2N:shared_process":[],"2DGEZGVZY:shared_process":[],"2DHFQ3SEW:shared_process":[]},"config":{"looknfeel":"default","personalizedMode":"false"},"info":{}}