previous article<\/a> to calculate the residual sum of squares.<\/p>\n\n\n\nimport numpy as np\nfrom sklearn.linear_model import LinearRegression\n\n# Training data\nX = [[6], [8], [10], [14], [18]]\ny = [[7], [9], [13], [17.5], [18]]\n\n# Create and fit the model\nmodel = LinearRegression()\nmodel.fit(X, y)\n\nprint 'A 12\" pizza should cost: $%.2f' % model.predict(12)[0]\n#A 12\" pizza should cost: $13.68\n\nprint np.mean((model.predict(X) - y) ** 2)\n#Residual sum of squares: 1.74956896552<\/code><\/pre>\n\n\n\nWe get 1.74 as our cost function or loss function which gives us the measure of error in our modal. The smaller the residual sum of squares, the better your model fits your data; The greater the residual sum of squares, the poorer your model fits your data. A value of zero means your model is a perfect fit.<\/p>\n","protected":false},"excerpt":{"rendered":"
Previously we derived a simple linear regression modal for our Pizza price dataset. We built a modal that predicted a price of $13.68 for a 12 inch pizza. When the same modal is used to predict the price of an 8 inch pizza, we get $9.78 which is around $0.78 more than the known price of $9. […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,6,32,31],"tags":[46,54,58,62],"_links":{"self":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/641"}],"collection":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":2,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":1897,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/posts\/641\/revisions\/1897"}],"wp:attachment":[{"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/write.muthu.co\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}