Python Programming CSEAIML
Python Programming CSEAIML
# open function
help(open)
file is either a text or byte string giving the name (and the path
if the file isn't in the current working directory) of the file to
be opened or an integer file descriptor of the file to be
wrapped. (If a file descriptor is given, it is closed when the
returned I/O object is closed, unless closefd is set to False.)
mode is an optional string that specifies the mode in which the file
is opened. It defaults to 'r' which means open for reading in text
mode. Other common values are 'w' for writing (truncating the file if
it already exists), 'x' for creating and writing to a new file, and
'a' for appending (which on some Unix systems, means that all writes
append to the end of the file regardless of the current seek position).
In text mode, if encoding is not specified the encoding used is platform
dependent: locale.getencoding() is called to get the current locale encoding.
(For reading and writing raw bytes use binary mode and leave encoding
unspecified.) The available modes are:
========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
========= ===============================================================
The default mode is 'rt' (open for reading text). For binary random
access, the mode 'w+b' opens and truncates the file to 0 bytes, while
'r+b' opens the file without truncation. The 'x' mode implies 'w' and
raises an `FileExistsError` if the file already exists.
* Binary files are buffered in fixed-size chunks; the size of the buffer
is chosen using a heuristic trying to determine the underlying device's
"block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
On many systems, the buffer will typically be 4096 or 8192 bytes long.
newline controls how universal newlines works (it only applies to text
mode). It can be None, '', '\n', '\r', and '\r\n'. It works as
follows:
open() returns a file object whose type depends on the mode, and
through which the standard file operations such as reading and writing
are performed. When open() is used to open a file in a text mode ('w',
'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
a file in a binary mode, the returned class varies: in read binary
mode, it returns a BufferedReader; in write binary and append binary
modes, it returns a BufferedWriter, and in read/write mode, it returns
a BufferedRandom.
['Line',
Out[50]:
'3',
'-',
'File',
'support',
'various',
'modes',
'for',
'reading',
'and',
'writing']
In [63]: print(file_obj.mode)
'''
first need to close the file
open file in required mode -
w - write - delete the existing content form file
a - append - add content at the end of file.
'''
file_obj.close()
file_obj.closed
file_obj.close()
file_obj = open("CSEAIML1_sample.txt")
file_obj.readlines()
r
['Line 1 - This is python class\n',
Out[63]:
'Line 2 - We are learning python file handling\n',
'Line 3 - File support various modes for reading and writing\n',
'Line 4 - Python programming\n',
'Line 5 - We are learning online classthe content write inside filethe content write in
side filethe content write inside filethe content write inside filethe content write ins
ide filethe content write inside filethe content write inside file']
In [29]: print(file_obj.mode)
'''
We first need to close the file
We open the file in required mode - write w/a
w - write inside the file while overiting the existing data
a - append the data at the end of file
'''
file_obj.close()
file_obj.closed
file_obj = open("CSEAIML1_sample.txt", 'a')
file_obj.write("text that we want to write inside file")
'''Returns the number of characters written (which is always equal to
the length of the string). '''
a
'Returns the number of characters written (which is always equal to\nthe length of the s
Out[29]:
tring). '
In [34]: file_obj.close()
file_obj.closed
file_obj = open("CSEAIML1_sample.txt")
file_obj.readlines()
In [ ]: file_obj.write()
In [19]: print(file_obj.mode)
file_obj.close()
file_obj = open("CSEAIML1_sample.txt", 'r')
# file_obj.write("We are learning online classes")
print(file_obj.read())
a+
Line 1 - This is python class
Line 2 - We are learning python file handling
Line 3 - File support various modes for reading and writing
Line 4 - Python programmingWe are learning online classesWe are learning online classes
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[1], line 6
4 list_file = file_obj.readlines()
5 ''' What is roll no of Ankit?'''
----> 6 str_var = list_file[2]
7 # print(str_var, type(str_var))
8 list_var = str_var.split()
In [ ]: # file_obj = open("CSEAIML1_sample.txt")
# file_obj.read(10)
# list_var = file_obj.readlines()
# list_var
In [ ]: str_var = list_var[2]
list_var2 = str_var.split()
list_var2[1:]
In [15]: import os
def create_file(filename):
try:
with open(filename, 'w') as f:
f.write('Hello, world!\n')
print("File " + filename + " created successfully.")
except IOError:
print("Error: could not create file " + filename)
def read_file(filename):
try:
with open(filename, 'r') as f:
contents = f.read()
print(contents)
except IOError:
print("Error: could not read file " + filename)
def delete_file(filename):
try:
os.remove(filename)
print("File " + filename + " deleted successfully.")
except IOError:
print("Error: could not delete file " + filename)
if __name__ == '__main__':
filename = "example.txt"
new_filename = "new_example.txt"
create_file(filename)
read_file(filename)
append_file(filename, "This is some additional text.\n")
read_file(filename)
rename_file(filename, new_filename)
read_file(new_filename)
delete_file(new_filename)
Excercise : Create a file with personal information using create, write, read, rename function.
file1.seek(0)
file1.seek(0)
file1.seek(0)
# readlines function
print("Output of Readlines function is ")
print(file1.readlines())
print()
file1.close()
# Append-adds at last
file1 = open("myfile.txt","a")#append mode
file1.write("Today \n")
file1.close()
file1 = open("myfile.txt","r")
print("Output of Readlines after appending")
print(file1.readlines())
print()
file1.close()
# Write-Overwrites
file1 = open("myfile.txt","w")#write mode
file1.write("Tomorrow \n")
file1.close()
file1 = open("myfile.txt","r")
print("Output of Readlines after writing")
print(file1.readlines())
print()
file1.close()
The Python File seek() method sets the file's cursor at a specified position in the current file. A file's cursor
is used to store the current position of the read and write operations in a file; and this method can move this
file cursor forward or backward.
For instance, whenever we open a file to read from it, the file cursor is always positioned at 0. It is gradually
incremented as we progress through the content of the file. But, some scenarios require the file to be read
from a particular position in the file. This is where this method comes into picture.
The seek() method sets the current file position in a file stream.
the syntax for the Python File seek() method fileObject.seek(offset[, whence])
offset -> A number representing the position to set the current file stream position. whence − (Optional) It
defaults to 0; which means absolute file positioning, other values are 1 which means seek relative to the
current position and 2 means seek relative to the file's end.
In [3]: # Change the current file position to 4, and return the rest of the line:
f = open("CSEAIML1_sample.txt", "r")
f.seek(4)
print(f.readline())
4 - Python programming
10
print(f.readline())
f.close()
20
ramming
In [10]: '''
Excercise:
Create a file
Add content inside the file
use seek() funciton
use tell() function
'''
'\nExcercise: \n Create a file \n Add content inside the file\n use seek() f
Out[10]:
unciton\n use tell() function \n'
Python Package?
Python Packages are a way to organize and structure your Python code into reusable components. Think of
it like a folder that contains related Python files (modules) that work together to provide certain functionality.
Packages help keep your code organized, make it easier to manage and maintain, and allow you to share
your code with others. They’re like a toolbox where you can store and organize your tools (functions and
classes) for easy access and reuse in different projects.
Installing Python Packages: Packages can be installed using the pip package manager,
e.g., pip install numpy.
Importing Packages: After installation, packages can be imported into Python scripts
using the import statement, e.g., import numpy as np.
Exploring Package Functionalities: Once imported, the functionalities provided by
packages can be explored and utilized.
Introduction to Matplotlib
Matplotlib is a plotting library for the Python programming language and its numerical mathematics
extension NumPy.
It provides an object-oriented API for embedding plots into applications.
Matplotlib produces high-quality figures suitable for publication.
Using Matplotlib
Installation: Matplotlib can be installed using pip, the Python package installer.
pip install matplotlib
Importing Matplotlib: In Python scripts, import the matplotlib.pyplot module to access
Matplotlib's plotting functions.
import matplotlib.pyplot as plt
Creating Basic Plots: Matplotlib provides various types of plots, such as line plots, scatter
plots, bar plots, histograms, etc.
Matplotlib Example: Matplotlib is a popular plotting library for Python. Below is a simple example of
how to create a basic plot using matplotlib.
In [9]: # Line Plot:
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Create a plot
plt.plot(x, y)
# Show plot
plt.show()
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Show plot
plt.show()
In [11]: # Bar Plot
import matplotlib.pyplot as plt
# Sample data
categories = ['A', 'B', 'C', 'D']
values = [10, 20, 15, 25]
# Show plot
plt.show()
In [13]: # Histogram
import matplotlib.pyplot as plt
import numpy as np
# Create a histogram
plt.hist(data, bins=30, color='orange', edgecolor='black')
# Show plot
plt.show()
In [15]: # Pie Chart
import matplotlib.pyplot as plt
# Sample data
sizes = [30, 20, 25, 15, 10]
labels = ['A', 'B', 'C', 'D', 'E']
# Add title
plt.title('Pie Chart Example')
# Show plot
plt.show()
In [19]: # Subplots
# import Matplotlib's pyplot module and NumPy library.
import matplotlib.pyplot as plt
import numpy as np
# Sample data
'''
Generate sample data for our plots. In this case,
x represents an array of values from 0 to 2π,
and y1 and y2 represent the sine and cosine values of x, respectively.
'''
x = np.linspace(0, 2 * np.pi, 400)
y1 = np.sin(x)
y2 = np.cos(x)
# Create subplots
'''
the subplots() function to create a figure (fig) and a set of subplots (axes).
The arguments (2, 1) indicate that we want to create 2 rows and 1 column of subplots.
'''
fig, axes = plt.subplots(2, 1)
# Adjust layout
'''
automatically adjust the layout of subplots to prevent overlapping labels, titles, etc.
'''
plt.tight_layout()
# Show plot
'''
display the plot containing both subplots.
'''
plt.show()
Installation
Numpy Example:
Here's a simple example of how to create and manipulate arrays using numpy.
# Creating a 1D array
arr1 = np.array([1, 2, 3, 4, 5])
print("1D array:", arr1)
# Creating a 2D array
arr2 = np.array([[1, 2, 3], [4, 5, 6]])
print("2D array:\n", arr2)
1D array: [1 2 3 4 5]
2D array:
[[1 2 3]
[4 5 6]]
Array Attributes
Number of dimensions: 2
Shape of the array: (2, 3)
Total number of elements: 6
Data type of elements: int32
Size of each element: 4
Original array: [1 2 3 4 5]
Sum of array elements: 15
Mean of array elements: 3.0
Maximum element: 5
Array Operations
# Universal functions
print("Sum of array:", np.sum(arr))
print("Mean of array:", np.mean(arr))
print("Square root of array:", np.sqrt(arr))
Array: [1 2 3 4]
Array + 2: [3 4 5 6]
Array * 2: [2 4 6 8]
Sum of array: 10
Mean of array: 2.5
Square root of array: [1. 1.41421356 1.73205081 2. ]
In [27]: # Slicing
print("First two elements:", arr[:2])
# Indexing
print("Element at index 1:", arr[1])
# Slicing 2D arrays
print("First row:", arr2[0, :])
print("Second column:", arr2[:, 1])
Reshaping Arrays
Reshaped array:
[[1 2]
[3 4]
[5 6]]
# Create an array
'''
Here, we create a 1D NumPy array called data with the elements [5, 10, 15, 20, 25].
'''
data = np.array([5, 10, 15, 20, 25])
# Perform element-wise operations
'''
This operation squares each element of the array data. The result is stored in data_squa
Element-wise squaring: [5^2, 10^2, 15^2, 20^2, 25^2] results in [25, 100, 225, 400, 625]
'''
data_squared = data ** 2
'''
This operation multiplies each element of the array data by 2. The result is stored in d
Element-wise doubling: [5*2, 10*2, 15*2, 20*2, 25*2] results in [10, 20, 30, 40, 50].
'''
data_doubled = data * 2
Pandas
Pandas is a powerful library for data manipulation and analysis in Python. It provides data
structures like Series and DataFrame which are essential for handling structured data.
Installation - pip install pandas
Importing Pandas - import pandas as pd
Pandas Example:
Here's a simple example of how to create a DataFrame and perform some basic operations
using pandas.
# Creating a Series
s = pd.Series([1, 3, 5, 7, 9])
print("Series:\n", s)
Series:
0 1
1 3
2 5
3 7
4 9
dtype: int64
In [41]: # DataFrame
# A DataFrame is a two-dimensional labeled data structure with columns of potentially di
# Creating a DataFrame
data = {
'Name': ['Ankit', 'Khusi', 'Pankaj'],
'Age': [24, 27, 22],
'City': ['New Delhi', 'Mumbai', 'Lucknow']
}
df = pd.DataFrame(data)
print("DataFrame:\n", df)
DataFrame:
Name Age City
0 Ankit 24 New Delhi
1 Khusi 27 Mumbai
2 Pankaj 22 Lucknow
DataFrame Attributes
DataFrame Operations
Selection: Selecting columns and rows.
Filtering: Filtering rows based on conditions.
Aggregation: Applying functions to DataFrame.
# Filtering rows
filtered_df = df[df['Age'] > 23]
print("Filtered DataFrame:\n", filtered_df)
# Aggregation
mean_age = df['Age'].mean()
print("Mean age:", mean_age)
Name column:
0 Ankit
1 Khusi
2 Pankaj
Name: Name, dtype: object
Name and Age columns:
Name Age
0 Ankit 24
1 Khusi 27
2 Pankaj 22
First row:
Name Ankit
Age 24
City New Delhi
Name: 0, dtype: object
Filtered DataFrame:
Name Age City
0 Ankit 24 New Delhi
1 Khusi 27 Mumbai
Mean age: 24.333333333333332
Data Cleaning
# Renaming columns
df_renamed = df.rename(columns={'Name': 'Full Name', 'Age': 'Years'})
print("Renamed DataFrame:\n", df_renamed)
# Removing duplicates
df_duplicates = df.append(df.iloc[0], ignore_index=True)
print("DataFrame with duplicates:\n", df_duplicates)
df_no_duplicates = df_duplicates.drop_duplicates()
print("DataFrame without duplicates:\n", df_no_duplicates)
Input/Output
# Writing to CSV
df.to_csv('output.csv', index=False)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[48], line 2
1 # Reading from CSV
----> 2 df_from_csv = pd.read_csv('example.csv')
3 print("DataFrame from CSV:\n", df_from_csv)
5 # Writing to CSV
# Sample data
data = {
'Name': ['Ankit', 'Barkha', 'Chirag', 'Dravid', 'Esha'],
'Age': [24, 27, 22, 32, 29],
'City': ['New Delhi', 'Lucknow', 'Kanpur', 'Gurgao', 'Lucknow'],
'Salary': [70000, 80000, 60000, 90000, 85000]
}
df = pd.DataFrame(data)
Original DataFrame:
Name Age City Salary
0 Ankit 24 New Delhi 70000
1 Barkha 27 Lucknow 80000
2 Chirag 22 Kanpur 60000
3 Dravid 32 Gurgao 90000
4 Esha 29 Lucknow 85000
Mean Salary: 77000.0
Filtered DataFrame (Age > 25):
Name Age City Salary
1 Barkha 27 Lucknow 80000
3 Dravid 32 Gurgao 90000
4 Esha 29 Lucknow 85000
Mean Salary by City:
City Salary
0 Gurgao 90000.0
1 Kanpur 60000.0
2 Lucknow 82500.0
3 New Delhi 70000.0
DataFrame with Age Group:
Name Age City Salary Age Group
0 Ankit 24 New Delhi 70000 20-25
1 Barkha 27 Lucknow 80000 25-30
2 Chirag 22 Kanpur 60000 20-25
3 Dravid 32 Gurgao 90000 30-35
4 Esha 29 Lucknow 85000 25-30
Installation
Tkinter is included with Python standard library, so no installation is required. If you
are using a Python distribution that does not include Tkinter, you can install it using
your package manager (for example, sudo apt-get install python3-tk on Debian-based
systems).
Importing Tkinter
import tkinter as tk
from tkinter import messagebox
def on_button_click(): # Defines a function that will be called when the button is click
messagebox.showinfo("Information", "Button Clicked!")
'''
Creates a button widget with the text "Click Me" that calls on_button_click when clicked
'''
button = tk.Button(root, text="Click Me", command=on_button_click)
button.pack(pady=10) # Packs the button into the window with 10 pixels of vertical paddin
# Add a label
# Creates and packs a label prompting the user to enter their name.
label = tk.Label(root, text="Enter your name:")
label.pack(pady=10)
# Add an entry
# Creates and packs an entry widget for the user to input their name.
entry = tk.Entry(root)
entry.pack(pady=10)
# Add a button
'''
Creates and packs a button that calls the show_name function when clicked.
'''
button = tk.Button(root, text="Submit", command=show_name)
button.pack(pady=10)
# Create a window
window = tk.Tk()
# Add a label
label = tk.Label(window, text="Hello, Tkinter!")
label.pack()
Tkinter Widgets
Tkinter provides a variety of widgets to create interactive user interfaces. Here are
some of the most commonly used widgets in Tkinter:
Label: Displays text or an image.
Button: Triggers an action when clicked.
Entry: A single-line text field for user input.
Text: A multi-line text field.
Frame: A container for other widgets.
Checkbutton: A checkbox widget.
Radiobutton: A radio button widget.
Listbox: Displays a list of items.
Scrollbar: Adds a scrollbar to another widget.
Menu: Creates a menu.
Scale: A slider for selecting a numeric value..
Combobox: A combination of a dropdown list and an entry field (requires ttk).
root = tk.Tk()
root.title("Label Example")
root.mainloop()
def on_button_click():
messagebox.showinfo("Information", "Button Clicked!")
root = tk.Tk()
root.title("Button Example")
root.mainloop()
root = tk.Tk()
root.title("Entry Example")
entry = tk.Entry(root)
entry.pack(pady=10)
root.mainloop()
root = tk.Tk()
root.title("Text Example")
root = tk.Tk()
root.title("Frame Example")
root.mainloop()
In [66]: # LabelFrame: A LabelFrame is a container widget like Frame, but with a label.
import tkinter as tk
root = tk.Tk()
root.title("LabelFrame Example")
root.mainloop()
root = tk.Tk()
root.title("Checkbutton Example")
check_var = tk.BooleanVar()
root.mainloop()
In [69]: # Radiobutton: A Radiobutton widget allows the user to select one option from a set of m
import tkinter as tk
root = tk.Tk()
root.title("Radiobutton Example")
radio_var = tk.IntVar()
root.mainloop()
root = tk.Tk()
root.title("Listbox Example")
listbox = tk.Listbox(root)
listbox.pack()
root.mainloop()
In [71]: # Scale: A Scale widget is a slider that allows the user to select a value from a range.
import tkinter as tk
root = tk.Tk()
root.title("Scale Example")
root.mainloop()
In [72]: # Scrollbar: A Scrollbar widget provides a way to scroll content that is too large to be
import tkinter as tk
root = tk.Tk()
root.title("Scrollbar Example")
text.config(yscrollcommand=scrollbar.set)
for i in range(100):
text.insert(tk.END, f"Line {i+1}\n")
root.mainloop()
root = tk.Tk()
root.title("Combobox Example")
root.mainloop()
def say_hello():
print("Hello!")
root = tk.Tk()
root.title("Menu Example")
menubar = tk.Menu(root)
root.config(menu=menubar)
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="New", command=say_hello)
file_menu.add_command(label="Exit", command=root.quit)
root.mainloop()
messagebox.showinfo("Information", msg)
# Label
label = tk.Label(root, text="Enter your name:")
label.pack(pady=5)
# Entry
name_entry = tk.Entry(root)
name_entry.pack(pady=5)
# Radiobuttons
radio_var = tk.IntVar()
radiobutton1 = tk.Radiobutton(root, text="Option 1", variable=radio_var, value=1)
radiobutton1.pack(pady=5)
radiobutton2 = tk.Radiobutton(root, text="Option 2", variable=radio_var, value=2)
radiobutton2.pack(pady=5)
# Checkbutton
check_var = tk.BooleanVar()
checkbutton = tk.Checkbutton(root, text="I agree", variable=check_var)
checkbutton.pack(pady=5)
# Combobox
combobox = ttk.Combobox(root, values=["Choice 1", "Choice 2", "Choice 3"])
combobox.pack(pady=5)
# Text
text = tk.Text(root, height=5, width=30)
text.pack(pady=5)
# Button
button = tk.Button(root, text="Submit", command=on_button_click)
button.pack(pady=20)
https://www.techradar.com/best/best-ide-for-python
https://www.geeksforgeeks.org/top-python-ide/
PyCharm
Visual Studio Code (VS Code)
Jupyter Notebook
Google Colab
Sublime Text
Spyder
Atom
Thonny
IDLE
PyDev (Eclipse)
Komodo Edit
Machine Learning
A basic machine learning application in Python using the popular scikit-learn library to
train a simple linear regression model:
# Splitting the dataset into 80% training and 20% testing sets
# The test_size parameter determines the proportion of the dataset to include in the tes
# The random_state parameter ensures reproducibility of the results
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42
# Making predictions
# Making predictions
y_pred = log_reg.predict(X_test)
Accuracy: 1.0
Classification Report:
precision recall f1-score support
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30
Random Forest Regression on Diabetes Dataset: Develop a regression model using the Random
Forest algorithm to predict the progression of diabetes in patients based on their baseline
characteristics. Utilize the Diabetes dataset containing 442 patient records with ten baseline
features, including age, sex, BMI, blood pressure, and six blood serum measurements. Train the
model to accurately estimate the future disease progression, facilitating the exploration and
evaluation of regression algorithms for predicting diabetes progression.
The Diabetes dataset contains 442 patient records with ten baseline features, such as age, sex, BMI,
blood pressure, and six blood serum measurements, alongside a quantitative measure of diabetes
progression one year after baseline. The problem formulation involves utilizing these features to
predict the progression of diabetes in patients. Specifically, it aims to develop a regression model
capable of accurately estimating the future disease progression based on the patient's baseline
characteristics. This dataset facilitates the exploration and evaluation of regression algorithms,
serving as a valuable resource for studying the relationship between patient attributes and the
progression of diabetes
Dataset information:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 442 entries, 0 to 441
Data columns (total 11 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 age 442 non-null float64
1 sex 442 non-null float64
2 bmi 442 non-null float64
3 bp 442 non-null float64
4 s1 442 non-null float64
5 s2 442 non-null float64
6 s3 442 non-null float64
7 s4 442 non-null float64
8 s5 442 non-null float64
9 s6 442 non-null float64
10 target 442 non-null float64
dtypes: float64(11)
memory usage: 38.1 KB
None
Summary statistics:
age sex bmi bp s1 \
count 4.420000e+02 4.420000e+02 4.420000e+02 4.420000e+02 4.420000e+02
mean -2.511817e-19 1.230790e-17 -2.245564e-16 -4.797570e-17 -1.381499e-17
std 4.761905e-02 4.761905e-02 4.761905e-02 4.761905e-02 4.761905e-02
min -1.072256e-01 -4.464164e-02 -9.027530e-02 -1.123988e-01 -1.267807e-01
25% -3.729927e-02 -4.464164e-02 -3.422907e-02 -3.665608e-02 -3.424784e-02
50% 5.383060e-03 -4.464164e-02 -7.283766e-03 -5.670422e-03 -4.320866e-03
75% 3.807591e-02 5.068012e-02 3.124802e-02 3.564379e-02 2.835801e-02
max 1.107267e-01 5.068012e-02 1.705552e-01 1.320436e-01 1.539137e-01
s2 s3 s4 s5 s6 \
count 4.420000e+02 4.420000e+02 4.420000e+02 4.420000e+02 4.420000e+02
mean 3.918434e-17 -5.777179e-18 -9.042540e-18 9.293722e-17 1.130318e-17
std 4.761905e-02 4.761905e-02 4.761905e-02 4.761905e-02 4.761905e-02
min -1.156131e-01 -1.023071e-01 -7.639450e-02 -1.260971e-01 -1.377672e-01
25% -3.035840e-02 -3.511716e-02 -3.949338e-02 -3.324559e-02 -3.317903e-02
50% -3.819065e-03 -6.584468e-03 -2.592262e-03 -1.947171e-03 -1.077698e-03
75% 2.984439e-02 2.931150e-02 3.430886e-02 3.243232e-02 2.791705e-02
max 1.987880e-01 1.811791e-01 1.852344e-01 1.335973e-01 1.356118e-01
target
count 442.000000
mean 152.133484
std 77.093005
min 25.000000
25% 87.000000
50% 140.500000
75% 211.500000
max 346.000000
C:\anaconda3\Lib\site-packages\seaborn\axisgrid.py:118: UserWarning: The figure layout h
as changed to tight
self._figure.tight_layout(*args, **kwargs)
# Making predictions
y_pred = rf_reg.predict(X_test)