Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 243005c

Browse files
Add files via upload (#21)
1 parent 167aa02 commit 243005c

File tree

7 files changed

+152
-0
lines changed

7 files changed

+152
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#1. Load the DataSet:
2+
import seaborn as sns
3+
iris_df = sns.load_dataset('iris')
4+
5+
#2. Exploratory Data Analysis (EDA):
6+
7+
print(iris_df.info())
8+
print(iris_df.describe())
9+
print(iris_df.head())
10+
11+
#3. Data Cleaning:
12+
13+
print(iris_df.isnull().sum())
14+
print(iris_df.duplicated().sum())
15+
16+
#4. Aggregation:
17+
18+
species_mean = iris_df.groupby('species').mean()
19+
20+
#5. Visualizations:
21+
22+
import matplotlib.pyplot as plt
23+
import seaborn as sns
24+
25+
sns.pairplot(iris_df, hue='species')
26+
plt.show()
27+
28+
sns.heatmap(iris_df.corr(), annot=True, cmap='coolwarm')
29+
plt.show()
30+
31+
#6. Correlation Calculations:
32+
33+
correlation_matrix = iris_df.corr()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#1. Load the Dataset:
2+
3+
from sklearn.datasets import load_boston
4+
boston = load_boston()
5+
6+
#2. Prepare the Data:
7+
8+
import pandas as pd
9+
10+
boston_df = pd.DataFrame(boston.data, columns=boston.feature_names)
11+
boston_df['PRICE'] = boston.target
12+
13+
X = boston_df.drop('PRICE', axis=1)
14+
y = boston_df['PRICE']
15+
16+
#3. Split the Data:
17+
18+
from sklearn.model_selection import train_test_split
19+
20+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
21+
22+
#4. Train the Model:
23+
24+
from sklearn.linear_model import LinearRegression
25+
26+
model = LinearRegression()
27+
model.fit(X_train, y_train)
28+
29+
#5. Evaluate the Model:
30+
31+
train_score = model.score(X_train, y_train)
32+
print(f'Training Score: {train_score}')
33+
34+
test_score = model.score(X_test, y_test)
35+
print(f'Testing Score: {test_score}')
36+
37+
#6. Plot Residuals:
38+
39+
import matplotlib.pyplot as plt
40+
41+
train_residuals = y_train - model.predict(X_train)
42+
test_residuals = y_test - model.predict(X_test)
43+
44+
plt.figure(figsize=(10, 5))
45+
plt.scatter(model.predict(X_train), train_residuals, label='Train Residuals', alpha=0.5)
46+
plt.scatter(model.predict(X_test), test_residuals, label='Test Residuals', alpha=0.5)
47+
plt.axhline(y=0, color='r', linestyle='--')
48+
plt.xlabel('Predicted Values')
49+
plt.ylabel('Residuals')
50+
plt.title('Residual Plot')
51+
plt.legend()
52+
plt.show()
65.8 KB
Loading[フレーム]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from PIL import Image
2+
import os
3+
4+
def compress_image(input_path, output_path, quality=60):
5+
"""
6+
Compresses an input image while maintaining quality.
7+
8+
Parameters:
9+
input_path (str): Path to the input image file.
10+
output_path (str): Path to save the compressed image file.
11+
quality (int): Compression quality (0 - 95). Default is 60.
12+
13+
Returns:
14+
None
15+
"""
16+
input_image = Image.open(input_path)
17+
18+
if input_image.mode == 'RGBA':
19+
input_image = input_image.convert('RGB')
20+
21+
compressed_image = input_image.copy()
22+
compressed_image.save(output_path, quality=quality)
23+
24+
print(f"Compressed image saved at: {output_path}")
25+
26+
def main():
27+
input_path = 'C:/Users/SATHVIK/OneDrive/Desktop/Motive.png'
28+
output_folder = 'compressed_images'
29+
os.makedirs(output_folder, exist_ok=True)
30+
31+
quality = 60
32+
33+
# Compress image
34+
output_path = os.path.join(output_folder, 'compressed_image.jpg')
35+
compress_image(input_path, output_path, quality)
36+
37+
if __name__ == "__main__":
38+
main()
39+
878 KB
Loading[フレーム]
918 KB
Loading[フレーム]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from PIL import Image
2+
import os
3+
4+
def convert_image(input_path, output_path, output_format):
5+
try:
6+
with Image.open(input_path) as img:
7+
img.save(output_path, format=output_format)
8+
print(f"Image converted successfully: {input_path} -> {output_path}")
9+
except Exception as e:
10+
print(f"Error converting image: {e}")
11+
12+
def main(input_folder, output_folder, output_format):
13+
if not os.path.exists(output_folder):
14+
os.makedirs(output_folder)
15+
16+
for filename in os.listdir(input_folder):
17+
input_path = os.path.join(input_folder, filename)
18+
19+
if os.path.isfile(input_path) and any(filename.lower().endswith(ext) for ext in ['.jpg', '.jpeg', '.png', '.bmp', '.gif']):
20+
output_filename = os.path.splitext(filename)[0] + '.' + output_format.lower()
21+
output_path = os.path.join(output_folder, output_filename)
22+
23+
convert_image(input_path, output_path, output_format)
24+
25+
input_folder = 'C:/Users/SATHVIK/OneDrive/Desktop'
26+
output_folder = 'output_images'
27+
output_format = 'PNG'
28+
main(input_folder, output_folder, output_format)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /