-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, 5 May 2023

urllib3 v2.0 only supports OpenSSL 1.1.1+

Error

lib\site-packages\urllib3\__init__.py in <module>
38 raise ImportError(
---> 39 "urllib3 v2.0 only supports OpenSSL 1.1.1+, currently "
40 f"the 'ssl' module is compiled with {ssl.OPENSSL_VERSION}. " ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.1.0h 27 Mar 2018. See: https://github.com/urllib3/urllib3/issues/2168

Solution

This error message is indicating that the version of OpenSSL installed on your system is too old to work with the version of urllib3 you are using. To fix this issue, you can either upgrade OpenSSL to version 1.1.1 or newer, or downgrade urllib3 to a version that is compatible with your current version of OpenSSL.

To upgrade OpenSSL, you can download and install the latest version of OpenSSL for your operating system from the OpenSSL website: https://www.openssl.org/source/

To downgrade urllib3, you can run the following command in your terminal or command prompt:

pip install urllib3==1.26.6

This will install version 1.26.6 of urllib3, which is compatible with OpenSSL 1.1.0.

Error installing Jupyter & pywinpty (Python)

Error installing Jupyter & pywinpty (Python) resolved

I'm trying to install Jupyter on Python 3.7 and seem to be stumbling over this error again and again;

winpty/cywinpty.c(598): fatal error C1083: Cannot open include file: 'winpty.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

I get the same error when attempting to install pywinpty via pip.

I have installed & reinstalled the build tools to no avail and the command window is elevated - any ideas?

UPDATE: Not quite resolved in 3.7 - but it worked fine in 3.6, I've rolled back.


  Missing build time requirements in pyproject.toml for pywinpty>=1.1.0; os_name
 == "nt" from https://files.pythonhosted.org/packages/d3/89/2b9113eabacfe3bbebcd
f95c24772e2267c7b6b9fed6e35bffba2080a4c1/pywinpty-2.0.10.tar.gz#sha256=cdbb5694c
f8c7242c2ecfaca35c545d31fa5d5814c3d67a4e628f803f680ebea (from terminado>=0.8.3->
notebook->jupyter): 'setuptools' and 'wheel'.
  This version of pip does not implement PEP 517 so it cannot build a wheel with
out 'setuptools' and 'wheel'.
  Cache entry deserialization failed, entry ignored


Solution:

Temporarily, until standard way does not work for Python 3.7, you can install pywinpty manually by using the prebuilt wheel from Gohlke's collection and then install jupyter with pip.

To install manually (from cmd or Powershell) use:  pip install drive:\path\to\the\wheel\pywinpty-0.5.4-cp37-cp37m-win_amd64.whl


Tuesday, 2 May 2023

Tutorial Step by step machine learning based land use classification using Python

Basic steps to perform machine learning based land use classification using Python:

  1. Data preparation: Gather data on land use from various sources such as satellite imagery, ground survey, or government data. Process the data to make sure it is in a format that can be easily used by machine learning algorithms.

  2. Feature extraction: Extract features from the data such as vegetation index, texture, or color information. This can be done using various Python libraries such as scikit-image or OpenCV.

  3. Data labeling: Label the data with the correct land use category. This can be done using various techniques such as supervised learning, semi-supervised learning, or unsupervised learning.

  4. Model training: Train the machine learning model using the labeled data. You can use various algorithms such as Decision Trees, Random Forest, or Support Vector Machines (SVM) to train your model.

  5. Model evaluation: Evaluate the performance of your model using metrics such as accuracy, precision, recall, and F1 score.

  6. Model deployment: Once you are satisfied with the performance of your model, you can deploy it for land use classification.

Here are some tutorials and resources that can help you with machine learning based land use classification using Python:

  1. Land Use Classification with Machine Learning - This tutorial provides a step-by-step guide to performing land use classification using machine learning in Python. It covers data preparation, feature extraction, model training, and evaluation. The tutorial also includes code examples and print screens to help you follow along.

  2. Machine Learning for Land Use and Land Cover Classification - This resource provides an overview of machine learning techniques for land use and land cover classification. It covers various algorithms and techniques such as SVM, Decision Trees, Random Forest, and Deep Learning. The resource also includes code examples and print screens to help you understand the concepts.

  3. Machine Learning with Python - This book provides an introduction to machine learning using Python. It covers various topics such as data preprocessing, feature extraction, model training, and evaluation. The book also includes code examples and print screens to help you understand the concepts.

I hope this helps you get started with machine learning based land use classification using Python. Good luck!


Here is a step-by-step guide on Machine Learning based Land Use Classification with Python using scikit-learn and TensorFlow libraries.

Step 1: Data Acquisition The first step in any machine learning project is acquiring the data. For land use classification, you can obtain satellite imagery data from public sources such as the US Geological Survey (USGS) or the European Space Agency (ESA). For this tutorial, we will use the Sentinel-2 satellite imagery data provided by ESA.

Step 2: Data Preprocessing Once you have obtained the satellite imagery data, you will need to preprocess it before using it for classification. The preprocessing steps include:

  1. Loading the data into a format that can be read by Python.
  2. Removing any clouds or atmospheric noise from the images.
  3. Resampling the data to a common resolution.
  4. Splitting the data into training and testing sets.

Here's an example of how to load and preprocess the data:

python
import rasterio import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler # Load the image and mask data with rasterio.open('image.tif') as src: image_data = src.read() with rasterio.open('mask.tif') as src: mask_data = src.read() # Remove clouds and atmospheric noise # ... # Resample the data # ... # Flatten the data into a 2D array image_data = np.transpose(image_data, (1, 2, 0)) mask_data = np.transpose(mask_data, (1, 2, 0)) rows, cols, bands = image_data.shape image_data = np.reshape(image_data, (rows * cols, bands)) mask_data = np.reshape(mask_data, (rows * cols,)) # Split the data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(image_data, mask_data, test_size=0.2, random_state=42) # Standardize the data scaler = StandardScaler() X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test)

Step 3: Feature Extraction In machine learning, the process of converting raw input data into a set of meaningful features is known as feature extraction. Feature extraction can be performed manually, or by using automated techniques such as principal component analysis (PCA) or independent component analysis (ICA).

Here's an example of how to perform feature extraction using PCA:

python
from sklearn.decomposition import PCA # Perform PCA on the training data pca = PCA(n_components=10) X_train_pca = pca.fit_transform(X_train) # Apply the same transformation to the test data X_test_pca = pca.transform(X_test)

Step 4: Training the Model Once the data has been preprocessed and feature extraction has been performed, the next step is to train the machine learning model. For land use classification, we will use the scikit-learn library to train a Random Forest Classifier.

python
from sklearn.ensemble import RandomForestClassifier # Train the random forest classifier clf = RandomForestClassifier(n_estimators=100, random_state=42) clf.fit(X_train_pca, y_train)

Step 5: Evaluating the Model Once the model has been trained, the next step is to evaluate its performance on the testing set. We will use the confusion matrix and classification report to evaluate the model's performance.

python
from sklearn.metrics import confusion_matrix, classification_report # Evaluate the model on the testing set y_pred = clf.predict(X_test_pca) print(confusion_matrix(y_test, y_pred)) print(classification_report(y_test, y

Rank

seo