A blog for computer science passionates.

Sunday, 8 July 2018

Regression

Hi Friends,


Welcome again,

Today We are going to learn about Regression. We have already learn a brief about regression. But now, we take deep dive into the regression. It is a very broad thing in ML.

So, let's start with regression.
Regression is a type of supervised learning, so it has input variable as well as output variable like classification, but regression works for statistical analysis on data. or we can say it is a statistical process  to estimate real values, such  as, prices of different cars.

Lets take an example of regression:

import csv
import numpy
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm
file_name="regression_ex.csv"
raw_data=open(file_name,"rt")
reader=csv.reader(raw_data,delimiter=',',quoting=csv.QUOTE_NONE)
x=list(reader)
data=numpy.array(x)
plt.scatter(data[1:,0],data[1:,1])

Output:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAGmVJREFUeJzt3XuUHGWZx/Hv5AJILiBkdiMXBdagJgFDgGTxQoAFFkQSUHwkBiEiYlR0jcCedQVWx4ML7GLQlUUwBy8sIA8oJEdAcBeIihIJhFuCgc2AiCFLQhRCgMBkZv+o6kmn05Ou7q6u6ar39zknJ9PV1f28b8/0M3XpqV9HX18fIiIShiGDPQAREcmOmr6ISEDU9EVEAqKmLyISEDV9EZGAqOmLiARETV9EJCBq+iIiAVHTFxEJyLDBHkAV+hNhEZHGdNRaoR2bPqtWrWr4sWPGjGHt2rUpjqZ96mluqtdutYpeL09z22233RKtp8M7IiIBUdMXEQmImr6ISEDU9EVEAqKmLyISkESf3jGzY4BvAUOB+e5+0QDrnQTcCBzs7kvMbC/gcWBFvMp97j6n6VGLiEhDajZ9MxsKXA4cBTwL3G9mC919ecV6o4AvAIsrnmKlu09Kabwi0iZ616yGBdeybsN6ekeMghmzGNI5drCHJTUk2dKfAvyv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lGY2GtgT6Cbla4HFvege4B4zexT4HLDM3Q8Z4CFpvveA/G3pn0S0e/c2d9/L3fcEniL6jT8lPuQxhOi3fr2HcpLWAhhvZtvHu59/Fy/7PbBP/IMPm7c86mZmncB3ge+4ex9RPvFn4q0mzGxfMxtBtLt4enwck/iHvlED1YB0X9udgOfjhn848LYmnqsef6D69y2Pda4Gutz90YrlO7H5JOvsNqg5H/g2cH+9W8nx+k502LHkN2z+QMUs4p/DeAv6d8C3gJ/VuZH3P8COZnYq9J/bupRoz+ROYE7p5HfZ+2s9MKqe+cSPf4eZjStbNAl4HOiMT/JiZsPNrHwP7aPx8vcRHX59sd66lfLW9GcSBbCX+wnRR6B+S3Qi8jGi5ly5Xpq1HHiE6LjiUoD4hONngZ+b2a+B/yM6yZRU6Tj7MqLDHncSnUSC6M2zHHgw3o2+Ehjm7j8n2spZEu8aNnKMuKRqjfi+qq+tmc03s0RbcPEbZyPRa3aQmS0heuPWPJFpZnPMbE5909myrrv/kSrft7RkVQfA3Z91929VuesSoi3ee4n2TLc13oe2dX8aNd39AeAltr21vi2XAuWf4vkC8In40ODHgX8ou+8G4BTqO7RDvFF1IvARM3sSeILovNM/E70nngEeMbOHid77EJ1ovt3M7q5zPiOBH5rZ8ngO44nOg5wEXBzXeIjogwwlfzaz3xBtBH6y8gkbUYi/yK38xMQgjmOku78cn5i8HHjS3ecN5pjahZm9G/ieu08pYt3Bml87M7PdiA5lvLPRT3uFzFL6+5FKedvSb3efireglhHt9l5ZY/0gxFvp1xOdpCpc3cGaXzuLD5csBr6iht9eCrGlLyIiyWhLX0QkIGr6IiIBUdMXEQmImr6ISEDU9EVEAqKmLyISkP8HtkOF8rWBZjMAAAAASUVORK5CYII=
Figure: Regression of Month wise Heatwave


So, This is a simple example of regression. in next article, we will learn different types of regression.

No comments:

Post a Comment