shimpiproductions-3.0


Nameshimpiproductions-3.0 JSON
Version 0.1 PyPI version JSON
download
home_pageNone
Summaryimport numpy as np
upload_time2024-04-27 12:28:30
maintainerNone
docs_urlNone
authorSarvesh Shimpi
requires_pythonNone
licenseNone
keywords python video stream video stream camera stream sockets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            '''import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.cluster import KMeans
from sklearn.linear_model import LinearRegression
from sklearn.metrics import accuracy_score, mean_squared_error


#----------------------------------------------------------------------------------------------------------#

X, y = make_blobs(n_samples=1000, centers=4, n_features=2, random_state=42)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap='viridis')
plt.title('Synthetic Dataset')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()


#----------------------------------------------------------------------------------------------------------#

# Pre-processing
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

#----------------------------------------------------------------------------------------------------------#

# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)

#----------------------------------------------------------------------------------------------------------#

# KNN Classification
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train, y_train)
knn_pred = knn.predict(X_test)
knn_accuracy = accuracy_score(y_test, knn_pred)


#----------------------------------------------------------------------------------------------------------#

# Decision Tree
dt = DecisionTreeClassifier()
dt.fit(X_train, y_train)
dt_pred = dt.predict(X_test)
dt_accuracy = accuracy_score(y_test, dt_pred)

#----------------------------------------------------------------------------------------------------------#


# SVM
svm = SVC(kernel='linear')
svm.fit(X_train, y_train)
svm_pred = svm.predict(X_test)
svm_accuracy = accuracy_score(y_test, svm_pred)


#----------------------------------------------------------------------------------------------------------#


# Random Forest
rf = RandomForestClassifier(n_estimators=100)
rf.fit(X_train, y_train)
rf_pred = rf.predict(X_test)
rf_accuracy = accuracy_score(y_test, rf_pred)

#----------------------------------------------------------------------------------------------------------#

# K-means Clustering
kmeans = KMeans(n_clusters=4)
kmeans.fit(X_scaled)
cluster_centers = kmeans.cluster_centers_


#----------------------------------------------------------------------------------------------------------#

# Linear Regression
lr = LinearRegression()
lr.fit(X_train, y_train)
lr_pred = lr.predict(X_test)
lr_rmse = mean_squared_error(y_test, lr_pred, squared=False)

classifiers = ['KNN', 'Decision Tree', 'SVM', 'Random Forest', 'Linear Regression']
accuracies = [knn_accuracy, dt_accuracy, svm_accuracy, rf_accuracy, lr_rmse]


plt.bar(classifiers, accuracies)
plt.xlabel('Classifiers')
plt.ylabel('Accuracy')
plt.title('Accuracy of Different Classifiers')
plt.show()

#----------------------------------------------------------------------------------------------------------#

#Desion Tree
from sklearn.tree import plot_tree

# Visualize decision tree
plt.figure(figsize=(12, 8))
plot_tree(dt, filled=True, feature_names=['Feature 1', 'Feature 2'], class_names=['Class 0', 'Class 1', 'Class 2', 'Class 3'])
plt.title('Decision Tree Visualization')
plt.show()

# Visualize one decision tree from random forest (change index to visualize different trees)
plt.figure(figsize=(12, 8))
plot_tree(rf.estimators_[0], filled=True, feature_names=['Feature 1', 'Feature 2'], class_names=['Class 0', 'Class 1', 'Class 2', 'Class 3'])
plt.title('Decision Tree from Random Forest')
plt.show()


#----------------------------------------------------------------------------------------------------------#

# Visualize SVM decision boundaries
plt.figure(figsize=(12, 8))
h = .02  # step size in the mesh
x_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1
y_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                     np.arange(y_min, y_max, h))

Z = svm.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)

# Plot the dataset
plt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')
plt.title('SVM Decision Boundaries')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()


#----------------------------------------------------------------------------------------------------------#

# Visualize KNN decision boundaries
plt.figure(figsize=(12, 8))
h = .02  # step size in the mesh
x_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1
y_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                     np.arange(y_min, y_max, h))

Z = knn.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)

# Plot the dataset
plt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')
plt.title('KNN Decision Boundaries')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()


#----------------------------------------------------------------------------------------------------------#

# Visualize K-means clustering
plt.figure(figsize=(12, 8))

# Plot the dataset
plt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis', alpha=0.5)

# Plot cluster centroids
plt.scatter(cluster_centers[:, 0], cluster_centers[:, 1], c='red', marker='x', s=100, label='Cluster Centroids')

plt.title('K-means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()
plt.show()


# Visualize Linear Regression
plt.figure(figsize=(12, 8))

# Plot the training data
plt.scatter(X_train[:, 0], y_train, color='blue', label='Training Data')

# Plot the test data
plt.scatter(X_test[:, 0], y_test, color='green', label='Test Data')

# Plot the regression line
plt.plot(X_test[:, 0], lr.predict(X_test), color='red', linewidth=2, label='Linear Regression')

plt.title('Linear Regression')
plt.xlabel('Feature 1')
plt.ylabel('Target Variable')
plt.legend()
plt.show()


#----------------------------------------------------------------------------------------------------------#

#K-fold

import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
import numpy as np

model = SVC(kernel='linear')

kfold = KFold(n_splits=5, shuffle=True, random_state=42)

scores = cross_val_score(model, X_train, y_train, cv=kfold)

plt.figure(figsize=(8, 6))
plt.plot(np.arange(1, 6), scores, marker='o', linestyle='-')
plt.xlabel('Fold')
plt.ylabel('Accuracy')
plt.title('K-Fold Cross-Validation Scores')
plt.grid(True)
plt.show()

#----------------------------------------------------------------------------------------------------------#

# Visualize SVM decision boundaries with polynomial kernel
svm_poly = SVC(kernel='poly', degree=3)  # Polynomial kernel with degree 3
svm_poly.fit(X_train, y_train)

plt.figure(figsize=(12, 8))
h = .02  # step size in the mesh
x_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1
y_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                     np.arange(y_min, y_max, h))

Z = svm_poly.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)

# Plot the dataset
plt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')
plt.title('SVM Decision Boundaries with Polynomial Kernel')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()
'''

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "shimpiproductions-3.0",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, video, stream, video stream, camera stream, sockets",
    "author": "Sarvesh Shimpi",
    "author_email": "sarveshshimpi18@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/54/81/4eb495391f36f0c5364dfb3511009dec8ed481f56595cbf14957164fe905/shimpiproductions-3.0-0.1.tar.gz",
    "platform": null,
    "description": "'''import numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom sklearn.datasets import make_blobs\r\nfrom sklearn.preprocessing import StandardScaler\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.neighbors import KNeighborsClassifier\r\nfrom sklearn.tree import DecisionTreeClassifier\r\nfrom sklearn.svm import SVC\r\nfrom sklearn.ensemble import RandomForestClassifier\r\nfrom sklearn.cluster import KMeans\r\nfrom sklearn.linear_model import LinearRegression\r\nfrom sklearn.metrics import accuracy_score, mean_squared_error\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\nX, y = make_blobs(n_samples=1000, centers=4, n_features=2, random_state=42)\r\nplt.scatter(X[:, 0], X[:, 1], c=y, cmap='viridis')\r\nplt.title('Synthetic Dataset')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Feature 2')\r\nplt.show()\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Pre-processing\r\nscaler = StandardScaler()\r\nX_scaled = scaler.fit_transform(X)\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Train-test split\r\nX_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# KNN Classification\r\nknn = KNeighborsClassifier(n_neighbors=5)\r\nknn.fit(X_train, y_train)\r\nknn_pred = knn.predict(X_test)\r\nknn_accuracy = accuracy_score(y_test, knn_pred)\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Decision Tree\r\ndt = DecisionTreeClassifier()\r\ndt.fit(X_train, y_train)\r\ndt_pred = dt.predict(X_test)\r\ndt_accuracy = accuracy_score(y_test, dt_pred)\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n\r\n# SVM\r\nsvm = SVC(kernel='linear')\r\nsvm.fit(X_train, y_train)\r\nsvm_pred = svm.predict(X_test)\r\nsvm_accuracy = accuracy_score(y_test, svm_pred)\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n\r\n# Random Forest\r\nrf = RandomForestClassifier(n_estimators=100)\r\nrf.fit(X_train, y_train)\r\nrf_pred = rf.predict(X_test)\r\nrf_accuracy = accuracy_score(y_test, rf_pred)\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# K-means Clustering\r\nkmeans = KMeans(n_clusters=4)\r\nkmeans.fit(X_scaled)\r\ncluster_centers = kmeans.cluster_centers_\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Linear Regression\r\nlr = LinearRegression()\r\nlr.fit(X_train, y_train)\r\nlr_pred = lr.predict(X_test)\r\nlr_rmse = mean_squared_error(y_test, lr_pred, squared=False)\r\n\r\nclassifiers = ['KNN', 'Decision Tree', 'SVM', 'Random Forest', 'Linear Regression']\r\naccuracies = [knn_accuracy, dt_accuracy, svm_accuracy, rf_accuracy, lr_rmse]\r\n\r\n\r\nplt.bar(classifiers, accuracies)\r\nplt.xlabel('Classifiers')\r\nplt.ylabel('Accuracy')\r\nplt.title('Accuracy of Different Classifiers')\r\nplt.show()\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n#Desion Tree\r\nfrom sklearn.tree import plot_tree\r\n\r\n# Visualize decision tree\r\nplt.figure(figsize=(12, 8))\r\nplot_tree(dt, filled=True, feature_names=['Feature 1', 'Feature 2'], class_names=['Class 0', 'Class 1', 'Class 2', 'Class 3'])\r\nplt.title('Decision Tree Visualization')\r\nplt.show()\r\n\r\n# Visualize one decision tree from random forest (change index to visualize different trees)\r\nplt.figure(figsize=(12, 8))\r\nplot_tree(rf.estimators_[0], filled=True, feature_names=['Feature 1', 'Feature 2'], class_names=['Class 0', 'Class 1', 'Class 2', 'Class 3'])\r\nplt.title('Decision Tree from Random Forest')\r\nplt.show()\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Visualize SVM decision boundaries\r\nplt.figure(figsize=(12, 8))\r\nh = .02  # step size in the mesh\r\nx_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1\r\ny_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1\r\nxx, yy = np.meshgrid(np.arange(x_min, x_max, h),\r\n                     np.arange(y_min, y_max, h))\r\n\r\nZ = svm.predict(np.c_[xx.ravel(), yy.ravel()])\r\nZ = Z.reshape(xx.shape)\r\nplt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)\r\n\r\n# Plot the dataset\r\nplt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')\r\nplt.title('SVM Decision Boundaries')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Feature 2')\r\nplt.show()\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Visualize KNN decision boundaries\r\nplt.figure(figsize=(12, 8))\r\nh = .02  # step size in the mesh\r\nx_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1\r\ny_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1\r\nxx, yy = np.meshgrid(np.arange(x_min, x_max, h),\r\n                     np.arange(y_min, y_max, h))\r\n\r\nZ = knn.predict(np.c_[xx.ravel(), yy.ravel()])\r\nZ = Z.reshape(xx.shape)\r\nplt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)\r\n\r\n# Plot the dataset\r\nplt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')\r\nplt.title('KNN Decision Boundaries')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Feature 2')\r\nplt.show()\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Visualize K-means clustering\r\nplt.figure(figsize=(12, 8))\r\n\r\n# Plot the dataset\r\nplt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis', alpha=0.5)\r\n\r\n# Plot cluster centroids\r\nplt.scatter(cluster_centers[:, 0], cluster_centers[:, 1], c='red', marker='x', s=100, label='Cluster Centroids')\r\n\r\nplt.title('K-means Clustering')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Feature 2')\r\nplt.legend()\r\nplt.show()\r\n\r\n\r\n# Visualize Linear Regression\r\nplt.figure(figsize=(12, 8))\r\n\r\n# Plot the training data\r\nplt.scatter(X_train[:, 0], y_train, color='blue', label='Training Data')\r\n\r\n# Plot the test data\r\nplt.scatter(X_test[:, 0], y_test, color='green', label='Test Data')\r\n\r\n# Plot the regression line\r\nplt.plot(X_test[:, 0], lr.predict(X_test), color='red', linewidth=2, label='Linear Regression')\r\n\r\nplt.title('Linear Regression')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Target Variable')\r\nplt.legend()\r\nplt.show()\r\n\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n#K-fold\r\n\r\nimport matplotlib.pyplot as plt\r\nfrom sklearn.model_selection import KFold\r\nfrom sklearn.model_selection import cross_val_score\r\nimport numpy as np\r\n\r\nmodel = SVC(kernel='linear')\r\n\r\nkfold = KFold(n_splits=5, shuffle=True, random_state=42)\r\n\r\nscores = cross_val_score(model, X_train, y_train, cv=kfold)\r\n\r\nplt.figure(figsize=(8, 6))\r\nplt.plot(np.arange(1, 6), scores, marker='o', linestyle='-')\r\nplt.xlabel('Fold')\r\nplt.ylabel('Accuracy')\r\nplt.title('K-Fold Cross-Validation Scores')\r\nplt.grid(True)\r\nplt.show()\r\n\r\n#----------------------------------------------------------------------------------------------------------#\r\n\r\n# Visualize SVM decision boundaries with polynomial kernel\r\nsvm_poly = SVC(kernel='poly', degree=3)  # Polynomial kernel with degree 3\r\nsvm_poly.fit(X_train, y_train)\r\n\r\nplt.figure(figsize=(12, 8))\r\nh = .02  # step size in the mesh\r\nx_min, x_max = X_scaled[:, 0].min() - 1, X_scaled[:, 0].max() + 1\r\ny_min, y_max = X_scaled[:, 1].min() - 1, X_scaled[:, 1].max() + 1\r\nxx, yy = np.meshgrid(np.arange(x_min, x_max, h),\r\n                     np.arange(y_min, y_max, h))\r\n\r\nZ = svm_poly.predict(np.c_[xx.ravel(), yy.ravel()])\r\nZ = Z.reshape(xx.shape)\r\nplt.contourf(xx, yy, Z, cmap=plt.cm.viridis, alpha=0.8)\r\n\r\n# Plot the dataset\r\nplt.scatter(X_scaled[:, 0], X_scaled[:, 1], c=y, cmap='viridis')\r\nplt.title('SVM Decision Boundaries with Polynomial Kernel')\r\nplt.xlabel('Feature 1')\r\nplt.ylabel('Feature 2')\r\nplt.show()\r\n'''\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "import numpy as np",
    "version": "0.1",
    "project_urls": null,
    "split_keywords": [
        "python",
        " video",
        " stream",
        " video stream",
        " camera stream",
        " sockets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdf8e81f072de2569891774d7ef13386bb05591043903b72ecc02b1ee5de2950",
                "md5": "a9cb1f2d64e0580ac4e55fbaf1ad0285",
                "sha256": "c6a2afb50e5ad24fa15c24e57ac4bd9faf0d50536bfe79c64774e1656db83e54"
            },
            "downloads": -1,
            "filename": "shimpiproductions_3.0-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a9cb1f2d64e0580ac4e55fbaf1ad0285",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6169,
            "upload_time": "2024-04-27T12:28:27",
            "upload_time_iso_8601": "2024-04-27T12:28:27.056320Z",
            "url": "https://files.pythonhosted.org/packages/bd/f8/e81f072de2569891774d7ef13386bb05591043903b72ecc02b1ee5de2950/shimpiproductions_3.0-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54814eb495391f36f0c5364dfb3511009dec8ed481f56595cbf14957164fe905",
                "md5": "1627408c50154b261a5480727e346333",
                "sha256": "11ab517f5cd5140725183c40c737f9a25dd897474bd9ca8f3c7e3cdec9519542"
            },
            "downloads": -1,
            "filename": "shimpiproductions-3.0-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1627408c50154b261a5480727e346333",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4741,
            "upload_time": "2024-04-27T12:28:30",
            "upload_time_iso_8601": "2024-04-27T12:28:30.314912Z",
            "url": "https://files.pythonhosted.org/packages/54/81/4eb495391f36f0c5364dfb3511009dec8ed481f56595cbf14957164fe905/shimpiproductions-3.0-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 12:28:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "shimpiproductions-3.0"
}
        
Elapsed time: 0.23432s