scikit-tools 0.1.2__tar.gz → 0.2.0__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.
Files changed (33) hide show
  1. scikit_tools-0.2.0/PKG-INFO +61 -0
  2. scikit_tools-0.2.0/README.md +32 -0
  3. scikit_tools-0.2.0/SCIKIT_TOOLS.md +47 -0
  4. scikit_tools-0.2.0/pyproject.toml +22 -0
  5. scikit_tools-0.2.0/scikit_tools/__init__.py +1 -0
  6. scikit_tools-0.2.0/scikit_tools/correlation_covariance.py +19 -0
  7. scikit_tools-0.2.0/scikit_tools/data_transformation.py +26 -0
  8. scikit_tools-0.2.0/scikit_tools/descriptive_stats.py +24 -0
  9. scikit_tools-0.2.0/scikit_tools/eda_plots.py +34 -0
  10. scikit_tools-0.2.0/scikit_tools/hypothesis_testing.py +22 -0
  11. scikit_tools-0.2.0/scikit_tools/inspect_dataset.py +28 -0
  12. scikit_tools-0.2.0/scikit_tools/kmeans_clustering.py +29 -0
  13. scikit_tools-0.2.0/scikit_tools/linear_regression.py +32 -0
  14. scikit_tools-0.2.0/scikit_tools/logistic_regression.py +30 -0
  15. scikit_tools-0.2.0/scikit_tools/missing_values.py +33 -0
  16. scikit_tools-0.2.0/scikit_tools/numpy_stats.py +31 -0
  17. scikit_tools-0.2.0/scikit_tools/outlier_detection.py +39 -0
  18. scikit_tools-0.2.0/scikit_tools/pca.py +39 -0
  19. scikit_tools-0.2.0/scikit_tools.egg-info/PKG-INFO +61 -0
  20. scikit_tools-0.2.0/scikit_tools.egg-info/SOURCES.txt +24 -0
  21. {scikit_tools-0.1.2/src → scikit_tools-0.2.0}/scikit_tools.egg-info/requires.txt +5 -4
  22. {scikit_tools-0.1.2 → scikit_tools-0.2.0}/setup.cfg +4 -4
  23. scikit_tools-0.2.0/tests/test.py +31 -0
  24. scikit_tools-0.2.0/tests/test_scikit_tools.py +67 -0
  25. scikit_tools-0.1.2/PKG-INFO +0 -19
  26. scikit_tools-0.1.2/README.md +0 -2
  27. scikit_tools-0.1.2/pyproject.toml +0 -29
  28. scikit_tools-0.1.2/src/scikit_tools/__init__.py +0 -1
  29. scikit_tools-0.1.2/src/scikit_tools/solutions.py +0 -341
  30. scikit_tools-0.1.2/src/scikit_tools.egg-info/PKG-INFO +0 -19
  31. scikit_tools-0.1.2/src/scikit_tools.egg-info/SOURCES.txt +0 -9
  32. {scikit_tools-0.1.2/src → scikit_tools-0.2.0}/scikit_tools.egg-info/dependency_links.txt +0 -0
  33. {scikit_tools-0.1.2/src → scikit_tools-0.2.0}/scikit_tools.egg-info/top_level.txt +0 -0
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: scikit-tools
3
+ Version: 0.2.0
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, straight-through Python examples. Each
18
+ topic file contains its own imports, dataset setup, and analysis code; examples
19
+ are not hidden inside functions.
20
+
21
+ ## Install from a local checkout
22
+
23
+ ```console
24
+ python -m pip install -e .
25
+ ```
26
+
27
+ This installs the package and its dependencies. Each topic loads the Iris
28
+ dataset provided by `sklearn.datasets.load_iris`, formats its columns to match
29
+ the examples, and does not download or write a CSV file.
30
+
31
+ ## Open or run a topic
32
+
33
+ ```console
34
+ python -m scikit_tools.numpy_stats
35
+ python -m scikit_tools.pca
36
+ ```
37
+
38
+ You can also open any topic script under `scikit_tools` directly in your
39
+ editor, inspect or copy its raw code, and run it with the editor's Python run
40
+ command. These are scripts: importing one executes its example.
41
+
42
+ ## Topics
43
+
44
+ 1. NumPy statistics (`numpy_stats.py`)
45
+ 2. Inspecting the Iris dataset (`inspect_dataset.py`)
46
+ 3. Handling missing values (`missing_values.py`)
47
+ 4. Data transformation (`data_transformation.py`)
48
+ 5. Histogram and scatter-plot EDA (`eda_plots.py`)
49
+ 6. Box plot and IQR outlier detection (`outlier_detection.py`)
50
+ 7. Descriptive statistics (`descriptive_stats.py`)
51
+ 8. Correlation and covariance (`correlation_covariance.py`)
52
+ 9. Independent-samples t-test (`hypothesis_testing.py`)
53
+ 10. Linear regression (`linear_regression.py`)
54
+ 11. Logistic-regression classification (`logistic_regression.py`)
55
+ 12. K-means clustering (`kmeans_clustering.py`)
56
+ 13. PCA and classification (`pca.py`)
57
+
58
+ The examples use the Iris columns `SepalLengthCm`, `SepalWidthCm`,
59
+ `PetalLengthCm`, `PetalWidthCm`, and `Species`. The species names use the
60
+ `Iris-setosa` style. The missing values example intentionally adds missing values to a DataFrame
61
+ copy and fills them; it does not change the source dataset.
@@ -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,47 @@
1
+ # scikit-tools
2
+
3
+ `scikit-tools` provides 13 standalone, straight-through Python examples. Each
4
+ topic file contains its own imports, dataset setup, and analysis code; examples
5
+ are not hidden inside functions.
6
+
7
+ ## Install from a local checkout
8
+
9
+ ```console
10
+ python -m pip install -e .
11
+ ```
12
+
13
+ This installs the package and its dependencies. Each topic loads the Iris
14
+ dataset provided by `sklearn.datasets.load_iris`, formats its columns to match
15
+ the examples, and does not download or write a CSV file.
16
+
17
+ ## Open or run a topic
18
+
19
+ ```console
20
+ python -m scikit_tools.numpy_stats
21
+ python -m scikit_tools.pca
22
+ ```
23
+
24
+ You can also open any topic script under `scikit_tools` directly in your
25
+ editor, inspect or copy its raw code, and run it with the editor's Python run
26
+ command. These are scripts: importing one executes its example.
27
+
28
+ ## Topics
29
+
30
+ 1. NumPy statistics (`numpy_stats.py`)
31
+ 2. Inspecting the Iris dataset (`inspect_dataset.py`)
32
+ 3. Handling missing values (`missing_values.py`)
33
+ 4. Data transformation (`data_transformation.py`)
34
+ 5. Histogram and scatter-plot EDA (`eda_plots.py`)
35
+ 6. Box plot and IQR outlier detection (`outlier_detection.py`)
36
+ 7. Descriptive statistics (`descriptive_stats.py`)
37
+ 8. Correlation and covariance (`correlation_covariance.py`)
38
+ 9. Independent-samples t-test (`hypothesis_testing.py`)
39
+ 10. Linear regression (`linear_regression.py`)
40
+ 11. Logistic-regression classification (`logistic_regression.py`)
41
+ 12. K-means clustering (`kmeans_clustering.py`)
42
+ 13. PCA and classification (`pca.py`)
43
+
44
+ The examples use the Iris columns `SepalLengthCm`, `SepalWidthCm`,
45
+ `PetalLengthCm`, `PetalWidthCm`, and `Species`. The species names use the
46
+ `Iris-setosa` style. The missing values example intentionally adds missing values to a DataFrame
47
+ copy and fills them; it does not change the source dataset.
@@ -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.0"
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 @@
1
+ """Runnable, straight-through examples for 13 scikit-learn/data-analysis topics."""
@@ -0,0 +1,19 @@
1
+ import pandas as pd
2
+ from sklearn.datasets import load_iris
3
+
4
+ iris = load_iris(as_frame=True)
5
+ df = iris.data.rename(columns={
6
+ 'sepal length (cm)': 'SepalLengthCm',
7
+ 'sepal width (cm)': 'SepalWidthCm',
8
+ 'petal length (cm)': 'PetalLengthCm',
9
+ 'petal width (cm)': 'PetalWidthCm'
10
+ })
11
+ df['Species'] = iris.target.map({
12
+ index: f'Iris-{name}' for index, name in enumerate(iris.target_names)
13
+ })
14
+
15
+ covariance_val = df['PetalLengthCm'].cov(df['PetalWidthCm'])
16
+ correlation_val = df['PetalLengthCm'].corr(df['PetalWidthCm'])
17
+
18
+ print(f"Covariance: {covariance_val:.4f}")
19
+ print(f"Correlation Coefficient: {correlation_val:.4f}")
@@ -0,0 +1,26 @@
1
+ import pandas as pd
2
+ from IPython.display import display
3
+ from sklearn.datasets import load_iris
4
+ from sklearn.preprocessing import StandardScaler
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
+ # One-hot encoding for Species
18
+ df_encoded = pd.get_dummies(df, columns=['Species'])
19
+
20
+ # Standardize numerical attributes
21
+ num_cols = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']
22
+ scaler = StandardScaler()
23
+ df_encoded[num_cols] = scaler.fit_transform(df_encoded[num_cols])
24
+
25
+ print("--- Transformed Data Preview ---")
26
+ display(df_encoded.head())
@@ -0,0 +1,24 @@
1
+ import pandas as pd
2
+ from IPython.display import display
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
+ attributes = ['SepalLengthCm', 'PetalLengthCm']
17
+ stats_summary = pd.DataFrame({
18
+ 'Mean': df[attributes].mean(),
19
+ 'Median': df[attributes].median(),
20
+ 'Sample Variance': df[attributes].var(),
21
+ 'Standard Deviation': df[attributes].std()
22
+ })
23
+
24
+ display(stats_summary)
@@ -0,0 +1,34 @@
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ import seaborn as sns
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
+ plt.figure(figsize=(14, 5))
18
+
19
+ # Histogram
20
+ plt.subplot(1, 2, 1)
21
+ sns.histplot(data=df, x='PetalLengthCm', kde=True, color='skyblue')
22
+ plt.title('Histogram of PetalLengthCm')
23
+ plt.xlabel('Petal Length (cm)')
24
+ plt.ylabel('Frequency')
25
+
26
+ # Scatter Plot
27
+ plt.subplot(1, 2, 2)
28
+ sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm', hue='Species', palette='Set1')
29
+ plt.title('SepalLengthCm vs PetalLengthCm')
30
+ plt.xlabel('Sepal Length (cm)')
31
+ plt.ylabel('Petal Length (cm)')
32
+
33
+ plt.tight_layout()
34
+ plt.show()
@@ -0,0 +1,22 @@
1
+ import pandas as pd
2
+ from scipy import stats
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
+ setosa_sepal = df[df['Species'] == 'Iris-setosa']['SepalLengthCm']
17
+ versicolor_sepal = df[df['Species'] == 'Iris-versicolor']['SepalLengthCm']
18
+
19
+ t_stat, p_val = stats.ttest_ind(setosa_sepal, versicolor_sepal, equal_var=False)
20
+
21
+ print(f"T-statistic: {t_stat:.4f}")
22
+ print(f"P-value: {p_val:.4e}")
@@ -0,0 +1,28 @@
1
+ import pandas as pd
2
+ from IPython.display import display
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
+ print("--- First 5 Records ---")
17
+ display(df.head())
18
+
19
+ print(f"\nNumber of rows: {df.shape[0]}, Number of columns: {df.shape[1]}")
20
+
21
+ print("\n--- Column Names & Data Types ---")
22
+ print(df.dtypes)
23
+
24
+ print("\n--- Summary Statistics ---")
25
+ display(df.describe())
26
+
27
+ print("\nNumerical attributes: SepalLengthCm, SepalWidthCm, PetalLengthCm, PetalWidthCm")
28
+ print("Target column: Species")
@@ -0,0 +1,29 @@
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ import seaborn as sns
4
+ from IPython.display import display
5
+ from sklearn.datasets import load_iris
6
+ from sklearn.cluster import KMeans
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
+
21
+ kmeans = KMeans(n_clusters=3, random_state=42, n_init='auto')
22
+ df['Cluster'] = kmeans.fit_predict(X)
23
+
24
+ plt.figure(figsize=(6, 4))
25
+ sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm', hue='Cluster', palette='Set1')
26
+ plt.title('K-Means Clustering Assignments (k=3)')
27
+ plt.show()
28
+
29
+ display(df[['SepalLengthCm', 'PetalLengthCm', 'Species', 'Cluster']].head())
@@ -0,0 +1,32 @@
1
+ import pandas as pd
2
+ from IPython.display import display
3
+ from sklearn.datasets import load_iris
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.linear_model import LinearRegression
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
+ X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalWidthCm']]
19
+ y = df['PetalLengthCm']
20
+
21
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
22
+
23
+ model = LinearRegression()
24
+ model.fit(X_train, y_train)
25
+
26
+ predictions = model.predict(X_test)
27
+
28
+ print("Model Coefficients:", {col: coef for col, coef in zip(X.columns, model.coef_)})
29
+ print("Intercept:", model.intercept_)
30
+
31
+ results = pd.DataFrame({'Actual': y_test, 'Predicted': predictions})
32
+ display(results.head())
@@ -0,0 +1,30 @@
1
+ import pandas as pd
2
+ from sklearn.datasets import load_iris
3
+ from sklearn.model_selection import train_test_split
4
+ from sklearn.linear_model import LogisticRegression
5
+ from sklearn.metrics import accuracy_score, confusion_matrix
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
+ X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
19
+ y = df['Species']
20
+
21
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
22
+
23
+ clf = LogisticRegression(max_iter=200)
24
+ clf.fit(X_train, y_train)
25
+
26
+ y_pred = clf.predict(X_test)
27
+
28
+ print(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
29
+ print("\nConfusion Matrix:")
30
+ print(confusion_matrix(y_test, y_pred))
@@ -0,0 +1,33 @@
1
+ import pandas as pd
2
+ import numpy as np
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
+ df_copy = df.copy()
16
+
17
+ # Introduce missing values
18
+ df_copy.loc[[5, 10, 15], 'SepalLengthCm'] = np.nan
19
+ df_copy.loc[[20, 25], 'Species'] = np.nan
20
+
21
+ print("--- Missing Value Count Before Imputation ---")
22
+ print(df_copy.isnull().sum())
23
+
24
+ # Impute numerical missing values with median
25
+ median_sepal = df_copy['SepalLengthCm'].median()
26
+ df_copy['SepalLengthCm'] = df_copy['SepalLengthCm'].fillna(median_sepal)
27
+
28
+ # Impute categorical missing values with mode
29
+ mode_species = df_copy['Species'].mode()[0]
30
+ df_copy['Species'] = df_copy['Species'].fillna(mode_species)
31
+
32
+ print("\n--- Missing Value Count After Imputation ---")
33
+ print(df_copy.isnull().sum())
@@ -0,0 +1,31 @@
1
+ import pandas as pd
2
+ import numpy as np
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
+ # Select SepalLengthCm and convert to NumPy array
17
+ sepal_length = df['SepalLengthCm'].to_numpy()
18
+
19
+ # Calculate basic statistics
20
+ total_sum = np.sum(sepal_length)
21
+ mean_val = np.mean(sepal_length)
22
+ max_val = np.max(sepal_length)
23
+ min_val = np.min(sepal_length)
24
+ first_five = sepal_length[:5]
25
+
26
+ # Display results
27
+ print(f"Sum: {total_sum:.2f}")
28
+ print(f"Mean: {mean_val:.2f}")
29
+ print(f"Maximum: {max_val:.2f}")
30
+ print(f"Minimum: {min_val:.2f}")
31
+ print(f"First five values: {first_five}")
@@ -0,0 +1,39 @@
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ import seaborn as sns
4
+ from IPython.display import display
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
+ # Box Plot
19
+ plt.figure(figsize=(6, 4))
20
+ sns.boxplot(y=df['SepalWidthCm'], color='lightgreen')
21
+ plt.title('Box Plot of SepalWidthCm')
22
+ plt.ylabel('Sepal Width (cm)')
23
+ plt.show()
24
+
25
+ # Calculate IQR & Outliers
26
+ Q1 = df['SepalWidthCm'].quantile(0.25)
27
+ Q3 = df['SepalWidthCm'].quantile(0.75)
28
+ IQR = Q3 - Q1
29
+ lower_bound = Q1 - 1.5 * IQR
30
+ upper_bound = Q3 + 1.5 * IQR
31
+
32
+ outliers = df[(df['SepalWidthCm'] < lower_bound) | (df['SepalWidthCm'] > upper_bound)]
33
+
34
+ print(f"Q1 (25th percentile): {Q1:.2f}")
35
+ print(f"Q3 (75th percentile): {Q3:.2f}")
36
+ print(f"IQR (Interquartile Range): {IQR:.2f}")
37
+ print(f"Outlier limits: {lower_bound:.2f} to {upper_bound:.2f}")
38
+ print(f"\nDetected Outliers:")
39
+ display(outliers[['SepalWidthCm', 'Species']])
@@ -0,0 +1,39 @@
1
+ import pandas as pd
2
+ from sklearn.datasets import load_iris
3
+ from sklearn.preprocessing import StandardScaler
4
+ from sklearn.decomposition import PCA
5
+ from sklearn.model_selection import train_test_split
6
+ from sklearn.linear_model import LogisticRegression
7
+ from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
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
+ y = df['Species']
22
+
23
+ # Standardize
24
+ X_scaled = StandardScaler().fit_transform(X)
25
+
26
+ # PCA to 2 components
27
+ pca = PCA(n_components=2)
28
+ X_pca = pca.fit_transform(X_scaled)
29
+
30
+ X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=0.2, random_state=42)
31
+
32
+ clf = LogisticRegression()
33
+ clf.fit(X_train, y_train)
34
+ y_pred = clf.predict(X_test)
35
+
36
+ print(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
37
+ print(f"Precision (Macro): {precision_score(y_test, y_pred, average='macro'):.4f}")
38
+ print(f"Recall (Macro): {recall_score(y_test, y_pred, average='macro'):.4f}")
39
+ print(f"F1-Score (Macro): {f1_score(y_test, y_pred, average='macro'):.4f}")
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: scikit-tools
3
+ Version: 0.2.0
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, straight-through Python examples. Each
18
+ topic file contains its own imports, dataset setup, and analysis code; examples
19
+ are not hidden inside functions.
20
+
21
+ ## Install from a local checkout
22
+
23
+ ```console
24
+ python -m pip install -e .
25
+ ```
26
+
27
+ This installs the package and its dependencies. Each topic loads the Iris
28
+ dataset provided by `sklearn.datasets.load_iris`, formats its columns to match
29
+ the examples, and does not download or write a CSV file.
30
+
31
+ ## Open or run a topic
32
+
33
+ ```console
34
+ python -m scikit_tools.numpy_stats
35
+ python -m scikit_tools.pca
36
+ ```
37
+
38
+ You can also open any topic script under `scikit_tools` directly in your
39
+ editor, inspect or copy its raw code, and run it with the editor's Python run
40
+ command. These are scripts: importing one executes its example.
41
+
42
+ ## Topics
43
+
44
+ 1. NumPy statistics (`numpy_stats.py`)
45
+ 2. Inspecting the Iris dataset (`inspect_dataset.py`)
46
+ 3. Handling missing values (`missing_values.py`)
47
+ 4. Data transformation (`data_transformation.py`)
48
+ 5. Histogram and scatter-plot EDA (`eda_plots.py`)
49
+ 6. Box plot and IQR outlier detection (`outlier_detection.py`)
50
+ 7. Descriptive statistics (`descriptive_stats.py`)
51
+ 8. Correlation and covariance (`correlation_covariance.py`)
52
+ 9. Independent-samples t-test (`hypothesis_testing.py`)
53
+ 10. Linear regression (`linear_regression.py`)
54
+ 11. Logistic-regression classification (`logistic_regression.py`)
55
+ 12. K-means clustering (`kmeans_clustering.py`)
56
+ 13. PCA and classification (`pca.py`)
57
+
58
+ The examples use the Iris columns `SepalLengthCm`, `SepalWidthCm`,
59
+ `PetalLengthCm`, `PetalWidthCm`, and `Species`. The species names use the
60
+ `Iris-setosa` style. The missing values example intentionally adds missing values to a DataFrame
61
+ copy and fills them; it does not change the source dataset.
@@ -0,0 +1,24 @@
1
+ README.md
2
+ SCIKIT_TOOLS.md
3
+ pyproject.toml
4
+ scikit_tools/__init__.py
5
+ scikit_tools/correlation_covariance.py
6
+ scikit_tools/data_transformation.py
7
+ scikit_tools/descriptive_stats.py
8
+ scikit_tools/eda_plots.py
9
+ scikit_tools/hypothesis_testing.py
10
+ scikit_tools/inspect_dataset.py
11
+ scikit_tools/kmeans_clustering.py
12
+ scikit_tools/linear_regression.py
13
+ scikit_tools/logistic_regression.py
14
+ scikit_tools/missing_values.py
15
+ scikit_tools/numpy_stats.py
16
+ scikit_tools/outlier_detection.py
17
+ scikit_tools/pca.py
18
+ scikit_tools.egg-info/PKG-INFO
19
+ scikit_tools.egg-info/SOURCES.txt
20
+ scikit_tools.egg-info/dependency_links.txt
21
+ scikit_tools.egg-info/requires.txt
22
+ scikit_tools.egg-info/top_level.txt
23
+ tests/test.py
24
+ tests/test_scikit_tools.py
@@ -1,6 +1,7 @@
1
- pandas
2
- numpy
1
+ ipython
3
2
  matplotlib
4
- seaborn
5
- scipy
3
+ numpy
4
+ pandas
6
5
  scikit-learn
6
+ scipy
7
+ seaborn
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ from pathlib import Path
2
+ import scikit_tools as st
3
+
4
+ def pca_analysis(filepath='Iris.csv'):
5
+ """Topic 13: Standardize, compress with 2-Component PCA, and classify."""
6
+ import pandas as pd
7
+ from sklearn.preprocessing import StandardScaler
8
+ from sklearn.decomposition import PCA
9
+ from sklearn.model_selection import train_test_split
10
+ from sklearn.linear_model import LogisticRegression
11
+ from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
12
+ df = pd.read_csv(filepath)
13
+ X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
14
+ y = df['Species']
15
+ X_scaled = StandardScaler().fit_transform(X)
16
+ pca = PCA(n_components=2)
17
+ X_pca = pca.fit_transform(X_scaled)
18
+ X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=0.2, random_state=42)
19
+ clf = LogisticRegression()
20
+ clf.fit(X_train, y_train)
21
+ y_pred = clf.predict(X_test)
22
+ return {
23
+ 'accuracy': accuracy_score(y_test, y_pred),
24
+ 'precision': precision_score(y_test, y_pred, average='macro'),
25
+ 'recall': recall_score(y_test, y_pred, average='macro'),
26
+ 'f1_score': f1_score(y_test, y_pred, average='macro')
27
+ }
28
+
29
+
30
+ if __name__ == '__main__':
31
+ print(pca_analysis(Path(__file__).with_name('Iris.csv')))
@@ -0,0 +1,67 @@
1
+ import os
2
+ from pathlib import Path
3
+ import subprocess
4
+ import sys
5
+ import tempfile
6
+ import unittest
7
+
8
+
9
+ PROJECT_ROOT = Path(__file__).resolve().parents[1]
10
+ TOPIC_MODULES = [
11
+ "numpy_stats",
12
+ "inspect_dataset",
13
+ "missing_values",
14
+ "data_transformation",
15
+ "eda_plots",
16
+ "outlier_detection",
17
+ "descriptive_stats",
18
+ "correlation_covariance",
19
+ "hypothesis_testing",
20
+ "linear_regression",
21
+ "logistic_regression",
22
+ "kmeans_clustering",
23
+ "pca",
24
+ ]
25
+
26
+
27
+ class ScikitToolsScriptTests(unittest.TestCase):
28
+ def test_all_topics_run_from_a_clean_working_directory(self):
29
+ with tempfile.TemporaryDirectory() as working_dir:
30
+ env = os.environ.copy()
31
+ env["MPLBACKEND"] = "Agg"
32
+ env["PYTHONPATH"] = str(PROJECT_ROOT)
33
+ for idx, module in enumerate(TOPIC_MODULES, start=1):
34
+ with self.subTest(module=module):
35
+ result = subprocess.run(
36
+ [sys.executable, str(PROJECT_ROOT / "scikit_tools" / f"{module}.py")],
37
+ cwd=working_dir,
38
+ env=env,
39
+ capture_output=True,
40
+ text=True,
41
+ timeout=60,
42
+ )
43
+ self.assertEqual(
44
+ result.returncode,
45
+ 0,
46
+ msg=f"module {module} failed:\n{result.stdout}\n{result.stderr}",
47
+ )
48
+ self.assertFalse((Path(working_dir) / "iris.csv").exists())
49
+ if module == "missing_values":
50
+ after_imputation = result.stdout.split(
51
+ "--- Missing Value Count After Imputation ---", 1
52
+ )[1]
53
+ self.assertRegex(after_imputation, r"SepalLengthCm\s+0")
54
+ self.assertRegex(after_imputation, r"Species\s+0")
55
+
56
+ def test_every_topic_loads_the_bundled_sklearn_dataset(self):
57
+ for module in TOPIC_MODULES:
58
+ with self.subTest(module=module):
59
+ source = (PROJECT_ROOT / "scikit_tools" / f"{module}.py").read_text(
60
+ encoding="utf-8"
61
+ )
62
+ self.assertIn("from sklearn.datasets import load_iris", source)
63
+ self.assertNotIn("from ._common", source)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ unittest.main()
@@ -1,19 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: scikit-tools
3
- Version: 0.1.2
4
- Summary: Clean, dependency-managed toolkit with raw script segments and dataset handling options
5
- Author-email: Your Name <your.email@example.com>
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: License :: OSI Approved :: MIT License
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: pandas
12
- Requires-Dist: numpy
13
- Requires-Dist: matplotlib
14
- Requires-Dist: seaborn
15
- Requires-Dist: scipy
16
- Requires-Dist: scikit-learn
17
-
18
- # scikit-tools
19
- A clean, streamlined scientific data science toolkit with self-contained dataset fetching and direct topic interfaces.
@@ -1,2 +0,0 @@
1
- # scikit-tools
2
- A clean, streamlined scientific data science toolkit with self-contained dataset fetching and direct topic interfaces.
@@ -1,29 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "scikit-tools"
7
- version = "0.1.2"
8
- description = "Clean, dependency-managed toolkit with raw script segments and dataset handling options"
9
- authors = [
10
- { name="Your Name", email="your.email@example.com" }
11
- ]
12
- readme = "README.md"
13
- requires-python = ">=3.8"
14
- classifiers = [
15
- "Programming Language :: Python :: 3",
16
- "License :: OSI Approved :: MIT License",
17
- "Operating System :: OS Independent",
18
- ]
19
- dependencies = [
20
- "pandas",
21
- "numpy",
22
- "matplotlib",
23
- "seaborn",
24
- "scipy",
25
- "scikit-learn"
26
- ]
27
-
28
- [tool.setuptools.packages.find]
29
- where = ["src"]
@@ -1 +0,0 @@
1
- from .solutions import *
@@ -1,341 +0,0 @@
1
- # scikit-tools solutions library containing raw topic scripts
2
-
3
- DATASET_SETUP_CODE = """
4
- import os
5
- import pandas as pd
6
-
7
- # --- METHOD 1: Direct URL Download & Format (Default) ---
8
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
9
- print("Fetching dataset from URL...")
10
- df = pd.read_csv(url)
11
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
12
- df['Species'] = df['Species'].map(lambda x: f\"Iris-{x}\")
13
- df.to_csv('iris.csv', index=False)
14
-
15
- # --- METHOD 2: Colab File Upload (Alternative for custom/manual uploads) ---
16
- # from google.colab import files
17
- # uploaded = files.upload()
18
- # df = pd.read_csv('iris.csv')
19
-
20
- # --- METHOD 3: Standard Local Check ---
21
- # if os.path.exists('iris.csv'):
22
- # df = pd.read_csv('iris.csv')
23
- """
24
- """
25
- This library contains the raw code scripts for all 13 Data Science topics.
26
- """
27
-
28
- # Topic 1: Basic numerical operations and statistics using NumPy.
29
- numpy_stats_script = """
30
- import os
31
- import pandas as pd
32
- import numpy as np
33
-
34
- # Dataset Download and Setup
35
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
36
- df = pd.read_csv(url)
37
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
38
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
39
- df.to_csv('iris.csv', index=False)
40
-
41
- # Alternatively using Colab uploads:
42
- # from google.colab import files
43
- # uploaded = files.upload()
44
-
45
- # Load formatted data
46
- df = pd.read_csv('iris.csv')
47
- sepal_length = df['SepalLengthCm'].to_numpy()
48
-
49
- total_sum = np.sum(sepal_length)
50
- mean_val = np.mean(sepal_length)
51
- max_val = np.max(sepal_length)
52
- min_val = np.min(sepal_length)
53
- first_five = sepal_length[:5]
54
-
55
- print(f"Sum: {total_sum:.2f}")
56
- print(f"Mean: {mean_val:.2f}")
57
- print(f"Maximum: {max_val:.2f}")
58
- print(f"Minimum: {min_val:.2f}")
59
- print(f"First five values: {first_five}")
60
- """
61
-
62
- # Topic 2: Load DataFrame and inspect its structure, columns, and shape.
63
- inspect_dataset_script = """
64
- import os
65
- import pandas as pd
66
-
67
- # Dataset Download and Setup
68
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
69
- df = pd.read_csv(url)
70
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
71
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
72
- df.to_csv('iris.csv', index=False)
73
-
74
- # Load formatted data
75
- df = pd.read_csv('iris.csv')
76
-
77
- print("--- First 5 Records ---")
78
- print(df.head())
79
- print(f"\nNumber of rows: {df.shape[0]}, Number of columns: {df.shape[1]}")
80
- print("\n--- Column Names & Data Types ---")
81
- print(df.dtypes)
82
- print("\n--- Summary Statistics ---")
83
- print(df.describe())
84
- """
85
-
86
- # Topic 3: Introduce mock missing values and handle them using median and mode.
87
- handle_missing_values_script = """
88
- import os
89
- import pandas as pd
90
- import numpy as np
91
-
92
- # Dataset Download and Setup
93
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
94
- df = pd.read_csv(url)
95
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
96
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
97
- df.to_csv('iris.csv', index=False)
98
-
99
- df_copy = pd.read_csv('iris.csv').copy()
100
- df_copy.loc[[5, 10, 15], 'SepalLengthCm'] = np.nan
101
- df_copy.loc[[20, 25], 'Species'] = np.nan
102
-
103
- median_sepal = df_copy['SepalLengthCm'].median()
104
- df_copy['SepalLengthCm'] = df_copy['SepalLengthCm'].fillna(median_sepal)
105
- mode_species = df_copy['Species'].mode()[0]
106
- df_copy['Species'] = df_copy['Species'].fillna(mode_species)
107
- print(df_copy.isnull().sum())
108
- """
109
-
110
- # Topic 4: Perform one-hot encoding and standardization (scaling).
111
- data_transformation_script = """
112
- import os
113
- import pandas as pd
114
- from sklearn.preprocessing import StandardScaler
115
-
116
- # Dataset Download and Setup
117
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
118
- df = pd.read_csv(url)
119
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
120
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
121
- df.to_csv('iris.csv', index=False)
122
-
123
- df = pd.read_csv('iris.csv')
124
- df_encoded = pd.get_dummies(df, columns=['Species'])
125
- num_cols = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']
126
- scaler = StandardScaler()
127
- df_encoded[num_cols] = scaler.fit_transform(df_encoded[num_cols])
128
- print(df_encoded.head())
129
- """
130
-
131
- # Topic 5: Generate and render Histogram and Scatter Plots for EDA.
132
- eda_plots_script = """
133
- import os
134
- import pandas as pd
135
- import matplotlib.pyplot as plt
136
- import seaborn as sns
137
-
138
- # Dataset Download and Setup
139
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
140
- df = pd.read_csv(url)
141
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
142
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
143
- df.to_csv('iris.csv', index=False)
144
-
145
- df = pd.read_csv('iris.csv')
146
- fig, axes = plt.subplots(1, 2, figsize=(14, 5))
147
- sns.histplot(data=df, x='PetalLengthCm', kde=True, color='skyblue', ax=axes[0])
148
- axes[0].set_title('Histogram of PetalLengthCm')
149
- sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm', hue='Species', palette='Set1', ax=axes[1])
150
- axes[1].set_title('SepalLengthCm vs PetalLengthCm')
151
- plt.tight_layout()
152
- plt.show()
153
- """
154
-
155
- # Topic 6: Quantify outliers using Interquartile Range (IQR) bounds.
156
- outlier_detection_script = """
157
- import os
158
- import pandas as pd
159
-
160
- # Dataset Download and Setup
161
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
162
- df = pd.read_csv(url)
163
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
164
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
165
- df.to_csv('iris.csv', index=False)
166
-
167
- df = pd.read_csv('iris.csv')
168
- Q1 = df['SepalWidthCm'].quantile(0.25)
169
- Q3 = df['SepalWidthCm'].quantile(0.75)
170
- IQR = Q3 - Q1
171
- lower_bound = Q1 - 1.5 * IQR
172
- upper_bound = Q3 + 1.5 * IQR
173
- outliers = df[(df['SepalWidthCm'] < lower_bound) | (df['SepalWidthCm'] > upper_bound)]
174
- print(f"IQR: {IQR:.2f}")
175
- print(f"Limits: {lower_bound:.2f} to {upper_bound:.2f}")
176
- print(outliers[['SepalWidthCm', 'Species']])
177
- """
178
-
179
- # Topic 7: Calculate detailed descriptive metrics.
180
- descriptive_stats_script = """
181
- import os
182
- import pandas as pd
183
-
184
- # Dataset Download and Setup
185
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
186
- df = pd.read_csv(url)
187
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
188
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
189
- df.to_csv('iris.csv', index=False)
190
-
191
- df = pd.read_csv('iris.csv')
192
- attributes = ['SepalLengthCm', 'PetalLengthCm']
193
- stats_summary = pd.DataFrame({
194
- 'Mean': df[attributes].mean(),
195
- 'Median': df[attributes].median(),
196
- 'Sample Variance': df[attributes].var(),
197
- 'Standard Deviation': df[attributes].std()
198
- })
199
- print(stats_summary)
200
- """
201
-
202
- # Topic 8: Evaluate covariance and Pearson correlation coefficient.
203
- correlation_covariance_script = """
204
- import os
205
- import pandas as pd
206
-
207
- # Dataset Download and Setup
208
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
209
- df = pd.read_csv(url)
210
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
211
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
212
- df.to_csv('iris.csv', index=False)
213
-
214
- df = pd.read_csv('iris.csv')
215
- covariance_val = df['PetalLengthCm'].cov(df['PetalWidthCm'])
216
- correlation_val = df['PetalLengthCm'].corr(df['PetalWidthCm'])
217
- print(f"Covariance: {covariance_val:.4f}")
218
- print(f"Correlation Coefficient: {correlation_val:.4f}")
219
- """
220
-
221
- # Topic 9: Run an independent T-test on SepalLengthCm between Setosa and Versicolor.
222
- hypothesis_testing_script = """
223
- import os
224
- import pandas as pd
225
- from scipy import stats
226
-
227
- # Dataset Download and Setup
228
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
229
- df = pd.read_csv(url)
230
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
231
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
232
- df.to_csv('iris.csv', index=False)
233
-
234
- df = pd.read_csv('iris.csv')
235
- setosa_sepal = df[df['Species'] == 'Iris-setosa']['SepalLengthCm']
236
- versicolor_sepal = df[df['Species'] == 'Iris-versicolor']['SepalLengthCm']
237
- t_stat, p_val = stats.ttest_ind(setosa_sepal, versicolor_sepal, equal_var=False)
238
- print(f"T-statistic: {t_stat:.4f}")
239
- print(f"P-value: {p_val:.4e}")
240
- """
241
-
242
- # Topic 10: Linear Regression predicting PetalLengthCm.
243
- linear_regression_script = """
244
- import os
245
- import pandas as pd
246
- from sklearn.model_selection import train_test_split
247
- from sklearn.linear_model import LinearRegression
248
-
249
- # Dataset Download and Setup
250
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
251
- df = pd.read_csv(url)
252
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
253
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
254
- df.to_csv('iris.csv', index=False)
255
-
256
- df = pd.read_csv('iris.csv')
257
- X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalWidthCm']]
258
- y = df['PetalLengthCm']
259
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
260
- model = LinearRegression()
261
- model.fit(X_train, y_train)
262
- predictions = model.predict(X_test)
263
- print("Model Coefficients:", model.coef_)
264
- print("Intercept:", model.intercept_)
265
- """
266
-
267
- # Topic 11: Multi-class Logistic Regression for classification.
268
- logistic_regression_script = """
269
- import os
270
- import pandas as pd
271
- from sklearn.model_selection import train_test_split
272
- from sklearn.linear_model import LogisticRegression
273
- from sklearn.metrics import accuracy_score, confusion_matrix
274
-
275
- # Dataset Download and Setup
276
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
277
- df = pd.read_csv(url)
278
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
279
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
280
- df.to_csv('iris.csv', index=False)
281
-
282
- df = pd.read_csv('iris.csv')
283
- X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
284
- y = df['Species']
285
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
286
- clf = LogisticRegression(max_iter=200)
287
- clf.fit(X_train, y_train)
288
- y_pred = clf.predict(X_test)
289
- print(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
290
- print(confusion_matrix(y_test, y_pred))
291
- """
292
-
293
- # Topic 12: Cluster attributes unsupervised using K-Means.
294
- kmeans_clustering_script = """
295
- import os
296
- import pandas as pd
297
- from sklearn.cluster import KMeans
298
-
299
- # Dataset Download and Setup
300
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
301
- df = pd.read_csv(url)
302
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
303
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
304
- df.to_csv('iris.csv', index=False)
305
-
306
- df = pd.read_csv('iris.csv')
307
- X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
308
- kmeans = KMeans(n_clusters=3, random_state=42, n_init='auto')
309
- df['Cluster'] = kmeans.fit_predict(X)
310
- print(df.head())
311
- """
312
-
313
- # Topic 13: Standardize, compress with 2-Component PCA, and classify.
314
- pca_analysis_script = """
315
- import os
316
- import pandas as pd
317
- from sklearn.preprocessing import StandardScaler
318
- from sklearn.decomposition import PCA
319
- from sklearn.model_selection import train_test_split
320
- from sklearn.linear_model import LogisticRegression
321
- from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
322
-
323
- # Dataset Download and Setup
324
- url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv'
325
- df = pd.read_csv(url)
326
- df.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']
327
- df['Species'] = df['Species'].map(lambda x: f"Iris-{x}")
328
- df.to_csv('iris.csv', index=False)
329
-
330
- df = pd.read_csv('iris.csv')
331
- X = df[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']]
332
- y = df['Species']
333
- X_scaled = StandardScaler().fit_transform(X)
334
- pca = PCA(n_components=2)
335
- X_pca = pca.fit_transform(X_scaled)
336
- X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=0.2, random_state=42)
337
- clf = LogisticRegression()
338
- clf.fit(X_train, y_train)
339
- y_pred = clf.predict(X_test)
340
- print(f"Accuracy: {accuracy_score(y_test, y_pred):.4f}")
341
- """
@@ -1,19 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: scikit-tools
3
- Version: 0.1.2
4
- Summary: Clean, dependency-managed toolkit with raw script segments and dataset handling options
5
- Author-email: Your Name <your.email@example.com>
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: License :: OSI Approved :: MIT License
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: pandas
12
- Requires-Dist: numpy
13
- Requires-Dist: matplotlib
14
- Requires-Dist: seaborn
15
- Requires-Dist: scipy
16
- Requires-Dist: scikit-learn
17
-
18
- # scikit-tools
19
- A clean, streamlined scientific data science toolkit with self-contained dataset fetching and direct topic interfaces.
@@ -1,9 +0,0 @@
1
- README.md
2
- pyproject.toml
3
- src/scikit_tools/__init__.py
4
- src/scikit_tools/solutions.py
5
- src/scikit_tools.egg-info/PKG-INFO
6
- src/scikit_tools.egg-info/SOURCES.txt
7
- src/scikit_tools.egg-info/dependency_links.txt
8
- src/scikit_tools.egg-info/requires.txt
9
- src/scikit_tools.egg-info/top_level.txt