- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can scikit-learn package be used to transform an array of specific size to a different size?
Scikit−learn, commonly known as sklearn is a library in Python that is used for the purpose of implementing machine learning algorithms. It is an open-source library hence it can be used free of cost. It is powerful and robust, since it provides a wide variety of tools to perform statistical modelling. This includes classification, regression, clustering, dimensionality reduction, and much more with the help of a powerful, and stable interface in Python. The library is built on Numpy, SciPy and Matplotlib libraries.
It can be installed using the ‘pip’ command as shown below −
pip install scikit−learn
This library focuses on data modelling. An array of different size can be transformed to an array of an entirely different size, using scikit−learn package.
Following is an example −
from sklearn.preprocessing import PolynomialFeatures import numpy as np Y = np.arange(12) print("The original dimensions of the ndarray") print(Y.shape) print("The changed dimensions of the ndarray") x = Y.reshape(3, 4) print(x.shape) poly = PolynomialFeatures(degree=2) print(poly.fit_transform(x))
The original dimensions of the ndarray (12,) The changed dimensions of the ndarray (3, 4) [[ 1. 0. 1. 2. 3. 0. 0. 0. 0. 1. 2. 3. 4. 6. 9.] [ 1. 4. 5. 6. 7. 16. 20. 24. 28. 25. 30. 35. 36. 42. 49.] [ 1. 8. 9. 10. 11. 64. 72. 80. 88. 81. 90. 99. 100. 110. 121.]]
The required packages are imported, and they are given alias names for ease of use.
The values for data points ‘x’ and ‘y’ are generated using NumPy library.
The details of the data generated is displayed on the console.
The ‘PolynomialFeatures’ function is called.
This function call is assigned to a variable.
This variable is fit to the model.
The data fit to the model is displayed on the console.
- How can scikit learn library be used to preprocess data in Python?
- How can scikit-learn library be used to load data in Python?
- How can scikit-learn library be used to get the resolution of an image in Python?
- How can scikit learn library be used to upload and view an image in Python?
- How can scikit-learn be used to convert an image from RGB to grayscale in Python?
- How can a specific tint be added to grayscale images in scikit-learn in Python?
- How can an input data array be transformed to a new data array using the process of streamlining using scikit-learn pipelining tools?
- How to generate an array for bi-clustering using Scikit-learn?
- How to transform Scikit-learn IRIS dataset to 2-feature dataset in Python?
- How to Install Python Scikit-learn on Different Operating Systems?
- Explain how scikit-learn library can be used to split the dataset for training and testing purposes in Python?
- How can data be scaled using scikit-learn library in Python?
- How to find contours of an image using scikit-learn in Python?
- Explain how L1 Normalization can be implemented using scikit-learn library in Python?
- Explain how L2 Normalization can be implemented using scikit-learn library in Python?