scikit-tools 0.1.2__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scikit_tools-0.2.1/PKG-INFO +79 -0
- scikit_tools-0.2.1/README.md +32 -0
- scikit_tools-0.2.1/SCIKIT_TOOLS.md +65 -0
- scikit_tools-0.2.1/pyproject.toml +22 -0
- scikit_tools-0.2.1/scikit_tools/__init__.py +32 -0
- scikit_tools-0.2.1/scikit_tools/correlation_covariance.py +24 -0
- scikit_tools-0.2.1/scikit_tools/data_transformation.py +31 -0
- scikit_tools-0.2.1/scikit_tools/descriptive_stats.py +29 -0
- scikit_tools-0.2.1/scikit_tools/eda_plots.py +39 -0
- scikit_tools-0.2.1/scikit_tools/hypothesis_testing.py +27 -0
- scikit_tools-0.2.1/scikit_tools/inspect_dataset.py +33 -0
- scikit_tools-0.2.1/scikit_tools/kmeans_clustering.py +34 -0
- scikit_tools-0.2.1/scikit_tools/linear_regression.py +37 -0
- scikit_tools-0.2.1/scikit_tools/logistic_regression.py +35 -0
- scikit_tools-0.2.1/scikit_tools/missing_values.py +38 -0
- scikit_tools-0.2.1/scikit_tools/numpy_stats.py +36 -0
- scikit_tools-0.2.1/scikit_tools/outlier_detection.py +44 -0
- scikit_tools-0.2.1/scikit_tools/pca.py +44 -0
- scikit_tools-0.2.1/scikit_tools.egg-info/PKG-INFO +79 -0
- scikit_tools-0.2.1/scikit_tools.egg-info/SOURCES.txt +24 -0
- {scikit_tools-0.1.2/src → scikit_tools-0.2.1}/scikit_tools.egg-info/requires.txt +5 -4
- {scikit_tools-0.1.2 → scikit_tools-0.2.1}/setup.cfg +4 -4
- scikit_tools-0.2.1/tests/test.py +8 -0
- scikit_tools-0.2.1/tests/test_scikit_tools.py +81 -0
- scikit_tools-0.1.2/PKG-INFO +0 -19
- scikit_tools-0.1.2/README.md +0 -2
- scikit_tools-0.1.2/pyproject.toml +0 -29
- scikit_tools-0.1.2/src/scikit_tools/__init__.py +0 -1
- scikit_tools-0.1.2/src/scikit_tools/solutions.py +0 -341
- scikit_tools-0.1.2/src/scikit_tools.egg-info/PKG-INFO +0 -19
- scikit_tools-0.1.2/src/scikit_tools.egg-info/SOURCES.txt +0 -9
- {scikit_tools-0.1.2/src → scikit_tools-0.2.1}/scikit_tools.egg-info/dependency_links.txt +0 -0
- {scikit_tools-0.1.2/src → scikit_tools-0.2.1}/scikit_tools.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scikit-tools
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Thirteen runnable, straight-through scikit-learn and data-analysis examples
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: ipython
|
|
8
|
+
Requires-Dist: matplotlib
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: pandas
|
|
11
|
+
Requires-Dist: scikit-learn
|
|
12
|
+
Requires-Dist: scipy
|
|
13
|
+
Requires-Dist: seaborn
|
|
14
|
+
|
|
15
|
+
# scikit-tools
|
|
16
|
+
|
|
17
|
+
`scikit-tools` provides 13 standalone, runnable Python examples for machine learning and data analysis. Each topic contains its own imports, dataset setup, and analysis code.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
pip install scikit-tools
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or from a local checkout:
|
|
26
|
+
|
|
27
|
+
```console
|
|
28
|
+
python -m pip install -e .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## How to Use
|
|
32
|
+
|
|
33
|
+
### 1. Inspect the Raw Source Code Without Running
|
|
34
|
+
Importing `scikit_tools` does not execute any calculations or open plots. You can access the complete standalone source code of any topic using `inspect`:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import inspect
|
|
38
|
+
import scikit_tools as st
|
|
39
|
+
|
|
40
|
+
# Prints the full raw code to the terminal
|
|
41
|
+
print(inspect.getsource(st.pca))
|
|
42
|
+
print(inspect.getsource(st.linear_regression))
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Run Directly in Python
|
|
46
|
+
Call any topic function directly:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import scikit_tools as st
|
|
50
|
+
|
|
51
|
+
st.pca()
|
|
52
|
+
st.numpy_stats()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 3. Run from Command Line
|
|
56
|
+
Run any topic as a standalone module:
|
|
57
|
+
|
|
58
|
+
```console
|
|
59
|
+
python -m scikit_tools.pca
|
|
60
|
+
python -m scikit_tools.numpy_stats
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Topics Available
|
|
64
|
+
|
|
65
|
+
1. NumPy statistics (`st.numpy_stats`)
|
|
66
|
+
2. Inspecting the Iris dataset (`st.inspect_dataset`)
|
|
67
|
+
3. Handling missing values (`st.missing_values`)
|
|
68
|
+
4. Data transformation (`st.data_transformation`)
|
|
69
|
+
5. Histogram and scatter-plot EDA (`st.eda_plots`)
|
|
70
|
+
6. Box plot and IQR outlier detection (`st.outlier_detection`)
|
|
71
|
+
7. Descriptive statistics (`st.descriptive_stats`)
|
|
72
|
+
8. Correlation and covariance (`st.correlation_covariance`)
|
|
73
|
+
9. Independent-samples t-test (`st.hypothesis_testing`)
|
|
74
|
+
10. Linear regression (`st.linear_regression`)
|
|
75
|
+
11. Logistic-regression classification (`st.logistic_regression`)
|
|
76
|
+
12. K-means clustering (`st.kmeans_clustering`)
|
|
77
|
+
13. PCA and classification (`st.pca`)
|
|
78
|
+
|
|
79
|
+
All examples load the Iris dataset via `sklearn.datasets.load_iris(as_frame=True)` with standardized column names (`SepalLengthCm`, `SepalWidthCm`, `PetalLengthCm`, `PetalWidthCm`, `Species`).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# IEEEXtreme Python Toolkit & OA / DSA Practice
|
|
2
|
+
|
|
3
|
+
A reusable, contest-oriented reference library and practice repository for advanced DSA, Online Assessments (OA), and competition simulations.
|
|
4
|
+
|
|
5
|
+
## DSA & OA Practice Problems
|
|
6
|
+
|
|
7
|
+
| # | Problem | Key Topics & Algorithms | Solutions |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| 01 | [Tree Vector Norm Maximization](problems/tree_vector_norm/EXPLANATION.md) | Tree DP, Convex Duality, QuickHull, Branch-and-Bound Pruning | [Python](problems/tree_vector_norm/solution.py), [C++](problems/tree_vector_norm/solution.cpp), [Tests](problems/tree_vector_norm/test_solution.py) |
|
|
10
|
+
|
|
11
|
+
## Toolkit Contents
|
|
12
|
+
|
|
13
|
+
- `template.py` — compact starting template suitable for copying into an editor.
|
|
14
|
+
- `io_utils.py` — fast token input, parsing, and output helpers.
|
|
15
|
+
- `sorting_searching.py`, `two_pointers.py` — common array patterns.
|
|
16
|
+
- `data_structures.py` — DSU, Fenwick and segment trees, trie, monotonic structures.
|
|
17
|
+
- `graphs.py`, `advanced_graphs.py` — traversals, shortest paths, MST, SCC, bridges, LCA, Euler tours.
|
|
18
|
+
- `dynamic_programming.py`, `number_theory.py`, `combinatorics.py`, `strings.py`, `geometry.py`, `bitwise.py`, `backtracking.py`.
|
|
19
|
+
- `docs/` — API notes, assumptions, and complexity guide.
|
|
20
|
+
- `tests/` — unit tests for representative edge cases and algorithms.
|
|
21
|
+
- `category_templates.py` — focused patterns mapped to every category visible in the supplied screenshot.
|
|
22
|
+
- `docs/category-map.md` — category-to-snippet index, archive research notes, and platform-use boundary.
|
|
23
|
+
|
|
24
|
+
## Use
|
|
25
|
+
|
|
26
|
+
Copy `template.py` as the actual contest starting file, then add only the needed algorithm snippets. Import library code locally while practicing, for example `from graphs import dijkstra`. Some contest editors accept only one submitted file, so copy required functions/classes into that file when needed. No package installation is required.
|
|
27
|
+
|
|
28
|
+
Run checks from this directory with `python -m unittest discover -s tests -v`.
|
|
29
|
+
|
|
30
|
+
## Notes
|
|
31
|
+
|
|
32
|
+
These are general algorithms, not task-specific solutions. Check each docstring for indexing, weight, and input assumptions. Python integers are arbitrary precision. Graph vertices and sequence positions are zero-indexed unless stated otherwise. Dijkstra requires nonnegative edge weights. The library is for local reference and practice; platform upload availability and competition rules are determined by the platform/organizers.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# scikit-tools
|
|
2
|
+
|
|
3
|
+
`scikit-tools` provides 13 standalone, runnable Python examples for machine learning and data analysis. Each topic contains its own imports, dataset setup, and analysis code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
pip install scikit-tools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or from a local checkout:
|
|
12
|
+
|
|
13
|
+
```console
|
|
14
|
+
python -m pip install -e .
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## How to Use
|
|
18
|
+
|
|
19
|
+
### 1. Inspect the Raw Source Code Without Running
|
|
20
|
+
Importing `scikit_tools` does not execute any calculations or open plots. You can access the complete standalone source code of any topic using `inspect`:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import inspect
|
|
24
|
+
import scikit_tools as st
|
|
25
|
+
|
|
26
|
+
# Prints the full raw code to the terminal
|
|
27
|
+
print(inspect.getsource(st.pca))
|
|
28
|
+
print(inspect.getsource(st.linear_regression))
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Run Directly in Python
|
|
32
|
+
Call any topic function directly:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import scikit_tools as st
|
|
36
|
+
|
|
37
|
+
st.pca()
|
|
38
|
+
st.numpy_stats()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 3. Run from Command Line
|
|
42
|
+
Run any topic as a standalone module:
|
|
43
|
+
|
|
44
|
+
```console
|
|
45
|
+
python -m scikit_tools.pca
|
|
46
|
+
python -m scikit_tools.numpy_stats
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Topics Available
|
|
50
|
+
|
|
51
|
+
1. NumPy statistics (`st.numpy_stats`)
|
|
52
|
+
2. Inspecting the Iris dataset (`st.inspect_dataset`)
|
|
53
|
+
3. Handling missing values (`st.missing_values`)
|
|
54
|
+
4. Data transformation (`st.data_transformation`)
|
|
55
|
+
5. Histogram and scatter-plot EDA (`st.eda_plots`)
|
|
56
|
+
6. Box plot and IQR outlier detection (`st.outlier_detection`)
|
|
57
|
+
7. Descriptive statistics (`st.descriptive_stats`)
|
|
58
|
+
8. Correlation and covariance (`st.correlation_covariance`)
|
|
59
|
+
9. Independent-samples t-test (`st.hypothesis_testing`)
|
|
60
|
+
10. Linear regression (`st.linear_regression`)
|
|
61
|
+
11. Logistic-regression classification (`st.logistic_regression`)
|
|
62
|
+
12. K-means clustering (`st.kmeans_clustering`)
|
|
63
|
+
13. PCA and classification (`st.pca`)
|
|
64
|
+
|
|
65
|
+
All examples load the Iris dataset via `sklearn.datasets.load_iris(as_frame=True)` with standardized column names (`SepalLengthCm`, `SepalWidthCm`, `PetalLengthCm`, `PetalWidthCm`, `Species`).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scikit-tools"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Thirteen runnable, straight-through scikit-learn and data-analysis examples"
|
|
9
|
+
readme = "SCIKIT_TOOLS.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"ipython",
|
|
13
|
+
"matplotlib",
|
|
14
|
+
"numpy",
|
|
15
|
+
"pandas",
|
|
16
|
+
"scikit-learn",
|
|
17
|
+
"scipy",
|
|
18
|
+
"seaborn",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
packages = ["scikit_tools"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Runnable, straight-through examples for 13 scikit-learn/data-analysis topics."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"correlation_covariance",
|
|
7
|
+
"data_transformation",
|
|
8
|
+
"descriptive_stats",
|
|
9
|
+
"eda_plots",
|
|
10
|
+
"hypothesis_testing",
|
|
11
|
+
"inspect_dataset",
|
|
12
|
+
"kmeans_clustering",
|
|
13
|
+
"linear_regression",
|
|
14
|
+
"logistic_regression",
|
|
15
|
+
"missing_values",
|
|
16
|
+
"numpy_stats",
|
|
17
|
+
"outlier_detection",
|
|
18
|
+
"pca",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def __getattr__(name: str):
|
|
23
|
+
if name in __all__:
|
|
24
|
+
module = importlib.import_module(f".{name}", __name__)
|
|
25
|
+
func = getattr(module, name)
|
|
26
|
+
globals()[name] = func
|
|
27
|
+
return func
|
|
28
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def __dir__():
|
|
32
|
+
return sorted(list(globals().keys()) + __all__)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
def correlation_covariance():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from sklearn.datasets import load_iris
|
|
4
|
+
|
|
5
|
+
iris = load_iris(as_frame=True)
|
|
6
|
+
df = iris.data.rename(columns={
|
|
7
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
8
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
9
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
10
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
11
|
+
})
|
|
12
|
+
df['Species'] = iris.target.map({
|
|
13
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
covariance_val = df['PetalLengthCm'].cov(df['PetalWidthCm'])
|
|
17
|
+
correlation_val = df['PetalLengthCm'].corr(df['PetalWidthCm'])
|
|
18
|
+
|
|
19
|
+
print(f"Covariance: {covariance_val:.4f}")
|
|
20
|
+
print(f"Correlation Coefficient: {correlation_val:.4f}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __name__ == '__main__':
|
|
24
|
+
correlation_covariance()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
def data_transformation():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from IPython.display import display
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
from sklearn.preprocessing import StandardScaler
|
|
6
|
+
|
|
7
|
+
iris = load_iris(as_frame=True)
|
|
8
|
+
df = iris.data.rename(columns={
|
|
9
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
10
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
11
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
12
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
13
|
+
})
|
|
14
|
+
df['Species'] = iris.target.map({
|
|
15
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
# One-hot encoding for Species
|
|
19
|
+
df_encoded = pd.get_dummies(df, columns=['Species'])
|
|
20
|
+
|
|
21
|
+
# Standardize numerical attributes
|
|
22
|
+
num_cols = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']
|
|
23
|
+
scaler = StandardScaler()
|
|
24
|
+
df_encoded[num_cols] = scaler.fit_transform(df_encoded[num_cols])
|
|
25
|
+
|
|
26
|
+
print("--- Transformed Data Preview ---")
|
|
27
|
+
display(df_encoded.head())
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == '__main__':
|
|
31
|
+
data_transformation()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
def descriptive_stats():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from IPython.display import display
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
|
|
6
|
+
iris = load_iris(as_frame=True)
|
|
7
|
+
df = iris.data.rename(columns={
|
|
8
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
9
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
10
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
11
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
12
|
+
})
|
|
13
|
+
df['Species'] = iris.target.map({
|
|
14
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
attributes = ['SepalLengthCm', 'PetalLengthCm']
|
|
18
|
+
stats_summary = pd.DataFrame({
|
|
19
|
+
'Mean': df[attributes].mean(),
|
|
20
|
+
'Median': df[attributes].median(),
|
|
21
|
+
'Sample Variance': df[attributes].var(),
|
|
22
|
+
'Standard Deviation': df[attributes].std()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
display(stats_summary)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == '__main__':
|
|
29
|
+
descriptive_stats()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
def eda_plots():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import seaborn as sns
|
|
5
|
+
from sklearn.datasets import load_iris
|
|
6
|
+
|
|
7
|
+
iris = load_iris(as_frame=True)
|
|
8
|
+
df = iris.data.rename(columns={
|
|
9
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
10
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
11
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
12
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
13
|
+
})
|
|
14
|
+
df['Species'] = iris.target.map({
|
|
15
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
plt.figure(figsize=(14, 5))
|
|
19
|
+
|
|
20
|
+
# Histogram
|
|
21
|
+
plt.subplot(1, 2, 1)
|
|
22
|
+
sns.histplot(data=df, x='PetalLengthCm', kde=True, color='skyblue')
|
|
23
|
+
plt.title('Histogram of PetalLengthCm')
|
|
24
|
+
plt.xlabel('Petal Length (cm)')
|
|
25
|
+
plt.ylabel('Frequency')
|
|
26
|
+
|
|
27
|
+
# Scatter Plot
|
|
28
|
+
plt.subplot(1, 2, 2)
|
|
29
|
+
sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm', hue='Species', palette='Set1')
|
|
30
|
+
plt.title('SepalLengthCm vs PetalLengthCm')
|
|
31
|
+
plt.xlabel('Sepal Length (cm)')
|
|
32
|
+
plt.ylabel('Petal Length (cm)')
|
|
33
|
+
|
|
34
|
+
plt.tight_layout()
|
|
35
|
+
plt.show()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
eda_plots()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
def hypothesis_testing():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from scipy import stats
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
|
|
6
|
+
iris = load_iris(as_frame=True)
|
|
7
|
+
df = iris.data.rename(columns={
|
|
8
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
9
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
10
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
11
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
12
|
+
})
|
|
13
|
+
df['Species'] = iris.target.map({
|
|
14
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
setosa_sepal = df[df['Species'] == 'Iris-setosa']['SepalLengthCm']
|
|
18
|
+
versicolor_sepal = df[df['Species'] == 'Iris-versicolor']['SepalLengthCm']
|
|
19
|
+
|
|
20
|
+
t_stat, p_val = stats.ttest_ind(setosa_sepal, versicolor_sepal, equal_var=False)
|
|
21
|
+
|
|
22
|
+
print(f"T-statistic: {t_stat:.4f}")
|
|
23
|
+
print(f"P-value: {p_val:.4e}")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == '__main__':
|
|
27
|
+
hypothesis_testing()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
def inspect_dataset():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from IPython.display import display
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
|
|
6
|
+
iris = load_iris(as_frame=True)
|
|
7
|
+
df = iris.data.rename(columns={
|
|
8
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
9
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
10
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
11
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
12
|
+
})
|
|
13
|
+
df['Species'] = iris.target.map({
|
|
14
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
print("--- First 5 Records ---")
|
|
18
|
+
display(df.head())
|
|
19
|
+
|
|
20
|
+
print(f"\nNumber of rows: {df.shape[0]}, Number of columns: {df.shape[1]}")
|
|
21
|
+
|
|
22
|
+
print("\n--- Column Names & Data Types ---")
|
|
23
|
+
print(df.dtypes)
|
|
24
|
+
|
|
25
|
+
print("\n--- Summary Statistics ---")
|
|
26
|
+
display(df.describe())
|
|
27
|
+
|
|
28
|
+
print("\nNumerical attributes: SepalLengthCm, SepalWidthCm, PetalLengthCm, PetalWidthCm")
|
|
29
|
+
print("Target column: Species")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == '__main__':
|
|
33
|
+
inspect_dataset()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
def kmeans_clustering():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import seaborn as sns
|
|
5
|
+
from IPython.display import display
|
|
6
|
+
from sklearn.datasets import load_iris
|
|
7
|
+
from sklearn.cluster import KMeans
|
|
8
|
+
|
|
9
|
+
iris = load_iris(as_frame=True)
|
|
10
|
+
df = iris.data.rename(columns={
|
|
11
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
12
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
13
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
14
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
15
|
+
})
|
|
16
|
+
df['Species'] = iris.target.map({
|
|
17
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
|
|
21
|
+
|
|
22
|
+
kmeans = KMeans(n_clusters=3, random_state=42, n_init='auto')
|
|
23
|
+
df['Cluster'] = kmeans.fit_predict(X)
|
|
24
|
+
|
|
25
|
+
plt.figure(figsize=(6, 4))
|
|
26
|
+
sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm', hue='Cluster', palette='Set1')
|
|
27
|
+
plt.title('K-Means Clustering Assignments (k=3)')
|
|
28
|
+
plt.show()
|
|
29
|
+
|
|
30
|
+
display(df[['SepalLengthCm', 'PetalLengthCm', 'Species', 'Cluster']].head())
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == '__main__':
|
|
34
|
+
kmeans_clustering()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
def linear_regression():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from IPython.display import display
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
from sklearn.model_selection import train_test_split
|
|
6
|
+
from sklearn.linear_model import LinearRegression
|
|
7
|
+
|
|
8
|
+
iris = load_iris(as_frame=True)
|
|
9
|
+
df = iris.data.rename(columns={
|
|
10
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
11
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
12
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
13
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
14
|
+
})
|
|
15
|
+
df['Species'] = iris.target.map({
|
|
16
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalWidthCm']]
|
|
20
|
+
y = df['PetalLengthCm']
|
|
21
|
+
|
|
22
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
23
|
+
|
|
24
|
+
model = LinearRegression()
|
|
25
|
+
model.fit(X_train, y_train)
|
|
26
|
+
|
|
27
|
+
predictions = model.predict(X_test)
|
|
28
|
+
|
|
29
|
+
print("Model Coefficients:", {col: coef for col, coef in zip(X.columns, model.coef_)})
|
|
30
|
+
print("Intercept:", model.intercept_)
|
|
31
|
+
|
|
32
|
+
results = pd.DataFrame({'Actual': y_test, 'Predicted': predictions})
|
|
33
|
+
display(results.head())
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == '__main__':
|
|
37
|
+
linear_regression()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
def logistic_regression():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from sklearn.datasets import load_iris
|
|
4
|
+
from sklearn.model_selection import train_test_split
|
|
5
|
+
from sklearn.linear_model import LogisticRegression
|
|
6
|
+
from sklearn.metrics import accuracy_score, confusion_matrix
|
|
7
|
+
|
|
8
|
+
iris = load_iris(as_frame=True)
|
|
9
|
+
df = iris.data.rename(columns={
|
|
10
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
11
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
12
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
13
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
14
|
+
})
|
|
15
|
+
df['Species'] = iris.target.map({
|
|
16
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
|
|
20
|
+
y = df['Species']
|
|
21
|
+
|
|
22
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
23
|
+
|
|
24
|
+
clf = LogisticRegression(max_iter=200)
|
|
25
|
+
clf.fit(X_train, y_train)
|
|
26
|
+
|
|
27
|
+
y_pred = clf.predict(X_test)
|
|
28
|
+
|
|
29
|
+
print(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
|
|
30
|
+
print("\nConfusion Matrix:")
|
|
31
|
+
print(confusion_matrix(y_test, y_pred))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == '__main__':
|
|
35
|
+
logistic_regression()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
def missing_values():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
|
|
6
|
+
iris = load_iris(as_frame=True)
|
|
7
|
+
df = iris.data.rename(columns={
|
|
8
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
9
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
10
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
11
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
12
|
+
})
|
|
13
|
+
df['Species'] = iris.target.map({
|
|
14
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
15
|
+
})
|
|
16
|
+
df_copy = df.copy()
|
|
17
|
+
|
|
18
|
+
# Introduce missing values
|
|
19
|
+
df_copy.loc[[5, 10, 15], 'SepalLengthCm'] = np.nan
|
|
20
|
+
df_copy.loc[[20, 25], 'Species'] = np.nan
|
|
21
|
+
|
|
22
|
+
print("--- Missing Value Count Before Imputation ---")
|
|
23
|
+
print(df_copy.isnull().sum())
|
|
24
|
+
|
|
25
|
+
# Impute numerical missing values with median
|
|
26
|
+
median_sepal = df_copy['SepalLengthCm'].median()
|
|
27
|
+
df_copy['SepalLengthCm'] = df_copy['SepalLengthCm'].fillna(median_sepal)
|
|
28
|
+
|
|
29
|
+
# Impute categorical missing values with mode
|
|
30
|
+
mode_species = df_copy['Species'].mode()[0]
|
|
31
|
+
df_copy['Species'] = df_copy['Species'].fillna(mode_species)
|
|
32
|
+
|
|
33
|
+
print("\n--- Missing Value Count After Imputation ---")
|
|
34
|
+
print(df_copy.isnull().sum())
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == '__main__':
|
|
38
|
+
missing_values()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
def numpy_stats():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
from sklearn.datasets import load_iris
|
|
5
|
+
|
|
6
|
+
iris = load_iris(as_frame=True)
|
|
7
|
+
df = iris.data.rename(columns={
|
|
8
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
9
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
10
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
11
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
12
|
+
})
|
|
13
|
+
df['Species'] = iris.target.map({
|
|
14
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
# Select SepalLengthCm and convert to NumPy array
|
|
18
|
+
sepal_length = df['SepalLengthCm'].to_numpy()
|
|
19
|
+
|
|
20
|
+
# Calculate basic statistics
|
|
21
|
+
total_sum = np.sum(sepal_length)
|
|
22
|
+
mean_val = np.mean(sepal_length)
|
|
23
|
+
max_val = np.max(sepal_length)
|
|
24
|
+
min_val = np.min(sepal_length)
|
|
25
|
+
first_five = sepal_length[:5]
|
|
26
|
+
|
|
27
|
+
# Display results
|
|
28
|
+
print(f"Sum: {total_sum:.2f}")
|
|
29
|
+
print(f"Mean: {mean_val:.2f}")
|
|
30
|
+
print(f"Maximum: {max_val:.2f}")
|
|
31
|
+
print(f"Minimum: {min_val:.2f}")
|
|
32
|
+
print(f"First five values: {first_five}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == '__main__':
|
|
36
|
+
numpy_stats()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
def outlier_detection():
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import seaborn as sns
|
|
5
|
+
from IPython.display import display
|
|
6
|
+
from sklearn.datasets import load_iris
|
|
7
|
+
|
|
8
|
+
iris = load_iris(as_frame=True)
|
|
9
|
+
df = iris.data.rename(columns={
|
|
10
|
+
'sepal length (cm)': 'SepalLengthCm',
|
|
11
|
+
'sepal width (cm)': 'SepalWidthCm',
|
|
12
|
+
'petal length (cm)': 'PetalLengthCm',
|
|
13
|
+
'petal width (cm)': 'PetalWidthCm'
|
|
14
|
+
})
|
|
15
|
+
df['Species'] = iris.target.map({
|
|
16
|
+
index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
# Box Plot
|
|
20
|
+
plt.figure(figsize=(6, 4))
|
|
21
|
+
sns.boxplot(y=df['SepalWidthCm'], color='lightgreen')
|
|
22
|
+
plt.title('Box Plot of SepalWidthCm')
|
|
23
|
+
plt.ylabel('Sepal Width (cm)')
|
|
24
|
+
plt.show()
|
|
25
|
+
|
|
26
|
+
# Calculate IQR & Outliers
|
|
27
|
+
Q1 = df['SepalWidthCm'].quantile(0.25)
|
|
28
|
+
Q3 = df['SepalWidthCm'].quantile(0.75)
|
|
29
|
+
IQR = Q3 - Q1
|
|
30
|
+
lower_bound = Q1 - 1.5 * IQR
|
|
31
|
+
upper_bound = Q3 + 1.5 * IQR
|
|
32
|
+
|
|
33
|
+
outliers = df[(df['SepalWidthCm'] < lower_bound) | (df['SepalWidthCm'] > upper_bound)]
|
|
34
|
+
|
|
35
|
+
print(f"Q1 (25th percentile): {Q1:.2f}")
|
|
36
|
+
print(f"Q3 (75th percentile): {Q3:.2f}")
|
|
37
|
+
print(f"IQR (Interquartile Range): {IQR:.2f}")
|
|
38
|
+
print(f"Outlier limits: {lower_bound:.2f} to {upper_bound:.2f}")
|
|
39
|
+
print(f"\nDetected Outliers:")
|
|
40
|
+
display(outliers[['SepalWidthCm', 'Species']])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == '__main__':
|
|
44
|
+
outlier_detection()
|