Q:

# How do you do linear regression in Python?

A:

Doing linear regression in python begins with looking at the correlation between two objects, such as alcohol and tobacco purchases in different regions. Copy the data, and paste it between pairs of triple quotes in the IPython Notebook. Wrap the data in a pandas Data frame, which gives you access to the whole variables.

## Keep Learning

1. Find the correlation between two variables

Look at a small data regarding the correlation between two products, such as the purchase of tobacco and alcohol in different regions within a place. Use this data to describe the tools used for calculating linear regression. Alternatively, you can use tools such as scikits-learn and stats models to calculate the linear regression and other tools such as pandas for managing data.

2. Import the modules

Copy the data, and paste it between a pair of three quotes in a notebook called IPython. End each line in a new line, and delimit each datum by a tab. Split the strings over the new lines before splitting each new datum using the tabs. Ensure all numbers register as numbers, and leave the strings for the regions only.

3. Wrap the data in a pandas data frame

Wrapping the data in the data frame allows you to access the whole variables using keywords. It has an excellent support for missing values and dates and is useful in plotting. Give two arguments for the data frame, and the column labels to allow you to refer to the two variables correctly using the labels.

Sources:

## Related Questions

• A: The Python math library contains a "sqrt(x)" function that returns the square root of a number. Another option is to type "x**(0.5)", which returns the sam... Full Answer >
Filed Under:
• A: The sqrt function in Python returns the square root of a given number. The syntax for the sqrt function is math.sqrt(x) where x equals any number greater t... Full Answer >
Filed Under:
• A: Introduced in Python 2.6, the math module provides a math.isnan() method that returns true if the argument is not a number as defined in the IEEE 754 stand... Full Answer >
Filed Under:
• A: Python floor() refers to the floor() method found within the math module in the popular programming language Python. The method returns a float of the near... Full Answer >
Filed Under:
PEOPLE SEARCH FOR