Search Results
Search this site
1009 results found with an empty search
- Research Paper Implementation : Recent Advances in Convolutional Neural Networks
ABSTRACT Abstract In the last few years, deep learning has led to very good performance on a variety of problems, such as visual recognition, speech recognition and natural language processing. Among different types of deep neural networks, convolutional neural networks have been most extensively studied. Leveraging on the rapid growth in the amount of the annotated data and the great improvements in the strengths of graphics processor units, the research on convolutional neural networks has been emerged swiftly and achieved stateof-the-art results on various tasks. In this paper, we provide a broad survey of the recent advances in convolutional neural networks. We detailize the improvements of CNN on different aspects, including layer design, activation function, loss function, regularization, optimization and fast computation. Besides, we also introduce various applications of convolutional neural networks in computer vision, speech and natural language processing. Keywords: Convolutional Neural Network, Deep learning. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Research Paper Implementation : Research Paper Recommender System Evaluation Using Coverage
ABSTRACT Recommendation systems(RS)support users and developers of various computer and software systems to overcome information overload, perform information discovery tasks and approximate computation, among others. Recommender systems research is frequently based on comparisons of predictive accuracy: the better the evaluation scores, the better the recommender. However, it is difficult to compare results from different recommender systems due to the many options in design and implementation of an evaluation strategy. Additionally, algorithmic implementations can separate from the standard formulation due to manual tuning and modifications that work better in some situations. It have been compared common recommendation algorithms as implemented in three popular recommendation frameworks. We evaluate the quality of recommender systems, most approaches only focus on the predictive accuracy of these systems. Recent works suggest that beyond accuracy there is a variety of other metrics that should be considered when evaluating a RS. This paper reviews a range of evaluation metrics and measures as well as some approaches used for evaluating recommendation systems. Analysis shows that large differences in recommendation accuracy across frameworks and strategies. we are developing the recommender system for research papers using coverage. Key Words Recommender System, Research Paper Recommender System, Evaluation, Metrics, Coverage. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Traffic Management System Using Java
Abstract The goal of this assignment is to implement a set of classes and interfaces1 to be used to create a simulation of a traffic management system. You will implement precisely the public and protected items described in the supplied documentation (no extra public/protected members or classes). Private members may be added at your own discretion. Language requirements: Java version 13, JUnit 4 Introduction In this assignment you will finish building a simple simulation of a traffic management system (TMS). A traffic management system monitors traffic flow in a region and adjusts traffic signals to optimise traffic flow. A TMS uses different types of sensors and signals to monitor and manage traffic flow. In the first assignment you implemented the core model for the TMS. In the second assignment you will implement some of the more advanced logic to provide a very simple simulation for the TMS. In addition to the pressure pads and speed cameras from assignment one, you willl add a vehicle count sensor. It counts vehicles passing a location and reports the traffic flow as the number of vehicles in a time period. You need to integrate this new type of sensor into the system. This is an example of a common situation when building a large system. New features need to be added to the system. A well designed system that uses interfaces to define an API means it should be simple to add the new feature. In assignment one, you implemented traffic lights and electronic speed signs and attached them to a route. In assignment two you will provide logic to coordinate traffic lights at intersections. The TMS monitors sensors along routes and manages signals on routes, and at intersections, to optimise traffic flow. In assignment one, the network of routes was implicitly defined by your test code and SimpleDisplay. In assignment two you will implement the logic for the TMS to maintain a network of routes. This includes the ability to load a network from a data file and save a modified network to a file. Monitoring and managing congestion requires sophisticated logic in a real TMS. In assignment one congestion was simply reported by each sensor. In assignment two you will implement logic for congestion calculators. These take the congestion data from a set of sensors and determine overall congestion for the route(s) covered by the sensors. The approach taken is to define a CongestionCalculator interface that provides an API. Different classes can implement this inter- face to provide different options for the logic of determining congestion. This is another example of a common approach to designing flexibility into the system’s structure. When implementing the assignment you need to remember that it is implementing a simulation of the TMS and not the real TMS. Interfaces are provided for the sensors to allow easy replacement of sensor implementations in the program. You will not be collecting data from real sensors but will be implementing classes that demonstrate the behaviour of sensors. They store a set of data values that are used to simulate the sensors returning different values over time. Signals are simple simulations of real signals, in that they only store the current state of the signal and allow the route to update the signal. To manage simulation of time, there is a TimedItem interface and a TimedItemManager class, which you implemented in assignment one. Sensors implement the TimedItem interface, as they are items which need to react to timed events. TimedItemManager stores all the TimedItem ob- jects in the application. The simulation’s GUI tracks time passing in MainView.run() and it invokes MainViewModel.tick() once per second. The tick method calls the TimedItemManager’s oneSecond method, which sends the oneSecond message to all TimedItems. This approach of tracking the passage of time and invoking an action on all relevant objects once per second was the reason that TimedItemManager is implemented as a singleton2 . A simple GUI has been provided to you as part of the provided code. It is in the tms.display package. It will not work until you have implemented the other parts of the assignment that it uses. The GUI has been implemented using JavaFX and consists of three classes and an enum. MainView creates the main window for the TMS GUI. StructureView displays the structure of the traffic network. MainViewModel represents the TMS model that is to be displayed. The TMS application is initialised and started by the Launcher class in the tms package. It loads the traffic network data and creates the GUI. Most of the GUI code has been provided to you. In MainViewModel you need to implement some of the logic that is executed by events in the simulation and to handle keyboard input for the main application’s window. The functionality you need to implement in MainViewModel is to: Save the state of the network to a file in response to the user selecting the save command. This is to be implemented in MainViewModel.save(). Allow the simulation’s execution to be paused and unpaused. This is to be implemented in MainViewModel.togglePaused(). Process time passing in the simulation. This is to be implemented in MainViewModel.tick(). Keyboard input is handled by the accept method in the MainViewModel class. It needs to process input from the user in the main window to perform actions in the simulation. Pressing the ‘P’ key will toggle whether the simulation is paused or not. The ‘Q’ key will quit the simulation. The ‘S’ key will save the current network to a file called “DefaultSave.txt”. A shell for this method has been provided because it is already hooked into the GUI. Persistent Data You need to implement loading a network from a data file. The JavaDoc for the loadNetwork method in the NetworkInitialiser class describes the format of a network data file. Saving a network is done by the save method in the MainViewModel class. A network data file is structured as follows: The first line is the number of intersections (ni) in the file. The second line is the number of routes in the file. The third line is the duration of a yellow light. The following ni lines are the intersection details. The first part of an intersection line is its id. This is optionally followed by a ‘:’, a duration, another ‘:’, and a sequence of intersection ids which are separated by commas. The final set of lines are the route details, including any sensors on the routes. – Each route is on a separate line. The sensors for a route are on the lines immediately after the line for the route. – A route is described by the id of the from intersection, followed by a ‘:’, then the id of the to intersection, followed by a ‘:’, then the default speed for the route, followed by a ‘:’, then the number of sensors on the route, then optionally a ‘:’ and the speed of the electronic speed sign on the route if it has one. – If the route has any sensors, each sensor follows on separate lines. – The first part of a sensor line is its type ‘PP’, ‘SC’ or ‘VC’. This is followed by a ‘:’, then its threshold value, a ‘:’, and then a comma separated list of the data values used to simulate the data returned by the sensor. Any line that starts with a semi-colon ‘;’ is a comment and is to be ignored when reading the data from the file. Attempting to read an invalid network data file should throw an InvalidNetworkException. An example data file, called demo.txt, is provided in your repository in the networks directory. It corresponds to the diagram below. Supplied Material This task sheet. An example network data file. Code specification document (Javadoc) A Subversion repositiory for submitting your assignment called ass2. A simple graphical user interface for the simulation, which is in the display package. A sample solution for the first assignment. You are to use this as the base for your implementation of the second assignment. As the first step in the assignment you should create a new project by checking out the ass2 repository from Subversion. Javadoc Code specifications are an important tool for developing code in collaboration with other people. Although assignments in this course are individual, they still aim to prepare you for writing code to a strict specification by providing a specification document (in Java, this is called Javadoc). You will need to implement the specification precisely as it is described in the specification document. The Javadoc can be viewed in either of the two following ways: 1. Open https://csse2002.uqcloud.net/assignment/2/ in your web browser. Note that this will only be the most recent version of the Javadoc. 2. Navigate to the relevant assignments folder under Assessment on Blackboard and you will be able to download the Javadoc .zip file containing html documentation. Unzip the bundle somewhere, and open docs/index.html with your web browser. Tags in the Javadoc indicate what code has been implemented in assignment one and what code you need to implement in assignment two. Some code from assignment one will need to be modified. There are tags indicating places where you can expect to modify the assignment one code but these are not guaranteed to be all of the places where you may end up modifying code from assignment one. Tasks 1. Implement the classes and methods described in the Javadoc as being requried for assignment two. 2. Implement the indicated features of the user interface. 3. Write JUnit 4 tests for all the methods in the following classes: AveragingCongestionCalculator (in a class called AveragingCongestionCalculatorTest) IntersectionLights (in a class called IntersectionLightsTest) NetworkInitialiser (in a class called NetworkInitialiserTest) Submission Submission is via your Subversion repository. You must ensure that you have committed your code to your repository before the submission deadline. Code that is submitted after the deadline will not be marked. Failure to submit your code through your repository will result in it not being marked. Details for how to submit your assignment are available in the Version Control Guide. Your repository url is: https://source.eait.uq.edu.au/svn/csse2002-s???????/trunk/ass2 — CSSE2002 students or https://source.eait.uq.edu.au/svn/csse7023-s???????/trunk/ass2 — CSSE7023 students Your submission should have the following internal structure: src/ folders (packages) and .java files for classes described in the Javadoc test/ folders (packages) and .java files for the JUnit test classes A complete submission would look like: src/tms/congestion/AveragingCongestionCalculator.java src/tms/congestion/CongestionCalculator.java src/tms/display/ButtonOptions.java src/tms/display/MainView.java src/tms/display/MainViewModel.java src/tms/display/StructureView.java src/tms/intersection/Intersection.java src/tms/intersection/IntersectionLights.java src/tms/network/Network.java src/tms/network/NetworkInitialiser.java src/tms/route/Route.java src/tms/route/SpeedSign.java src/tms/route/TrafficLight.java src/tms/route/TrafficSignal.java src/tms/sensors/DemoPressurePad.java src/tms/sensors/DemoSensor.java src/tms/sensors/DemoSpeedCamera.java src/tms/sensors/DemoVehicleCount.java src/tms/sensors/PressurePad.java src/tms/sensors/Sensor.java src/tms/sensors/SpeedCamera.java src/tms/sensors/VehicleCount.java src/tms/util/DuplicateSensorException.java src/tms/util/IntersectionNotFoundException.java src/tms/util/InvalidNetworkException.java src/tms/util/InvalidOrderException.java src/tms/util/RouteNotFoundException.java src/tms/util/TimedItem.java src/tms/util/TimedItemManager.java src/tms/Launcher.java test/tms/congestion/AveragingCongestionCalculatorTest.java test/tms/intersection/IntersectionLightsTest.java test/tms/network/NetworkInitialiserTest.java test/tms/JdkTest.java Ensure that your assignments correctly declare the package they are within. For example, CongestionCalculator.java should declare package tms.congestion. Do not submit any other files (e.g. no .class files). Note that AveragingCongestionCalculatorTest, IntersectionLightsTest and NetworkInitialiserTest will be compiled without the rest of your files. If you are looking solution of this project assignment then you can contact us at below contact detail, we will also provide other java related technology help: JavaFx, Spring, J2EE, etc. contact@codersarts.com
- Research Paper Implementation : New Thinking on, and with, Data Visualization.
ABSTRACT As the complexity and volume of datasets have increased along with the capabilities of modular, open-source, easy-to-implement, visualization tools, scientists’ need for, and appreciation of, data visualization has risen too. Until recently, scientists thought of the “explanatory” graphics created at a research project’s conclusion as “pretty pictures” needed only for journal publication or public outreach. The plots and displays produced during a research project--often intended only for experts--were thought of as a separate category, what we here call “exploratory” visualisation. In this view, discovery comes from exploratory visualisation, and explanatory visualisation is just for communication. Our aim in this paper is to spark conversation amongst scientists, computer scientists, outreach professionals, educators, and graphics and perception experts about how to foster flexible data visualisation practices that can facilitate discovery and communication at the same time. We present an example of a new finding made using the glue visualisation environment to demonstrate how the border between explanatory and exploratory visualisation is easily traversed. The linked-view principles as well as the actual code in glue are easily adapted to astronomy, medicine, and geographical information science--all fields where combining, visualising, and analysing several high-dimensional datasets yields insight. Whether or not scientists can use such a flexible “undisciplined” environment to its fullest potential without special training remains to be seen. We conclude with suggestions for improving the training of scientists in visualization practices, and of computer scientists in the iterative, non-workflow-like, ways in which modern science is carried out. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Linear Regression: Boston Housing data set
We will work with Boston housing data set which consists information about houses in Boston. It is provided in scikit-learn library. There are 506 samples and 13 feature variables in this dataset. The objective is to predict the value of prices of the house based on number of rooms. For this we will implement linear regression. First we will load the Boston data set from sklearn.datasets and then we will convert it into a dataframe using pandas so that we can easily work with it. We use NumPy to work with arrays.We will use matplotlib and seaborn to visualise the data. import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.datasets import load_boston %matplotlib inline from sklearn import datasets from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split, cross_val_score from sklearn.metrics import mean_squared_error boston= load_boston() boston.keys() Output: dict_keys(['data', 'target', 'feature_names', 'DESCR', 'filename']) data: contains the information for various houses target: prices of the house feature_names: names of the features DESCR: describes the data set bos = pd.DataFrame(boston.data, columns = boston.feature_names) bos['PRICE'] = boston.target bos.head() Now, we will explore the data to understand it better. We will look at the descriptive statistics of the data using the describe( ) function. bos.describe() We will plot a histogram of PRICE feature. sns.set(rc={'figure.figsize':(11.7,8.27)}) plt.hist(bos['PRICE'],color = 'red', bins=30) plt.xlabel("House prices in $1000") plt.show() We observe that the data is distributed normally and that there are only a few outliers. Next, we create a correlation matrix that measures the linear relationships between the variables. It can be done by using the function corr( ). We will use the heatmap function from the seaborn library to plot the correlation matrix. bos_1 = pd.DataFrame(boston.data, columns = boston.feature_names) bos_1['PRICE']=boston.target correlation_matrix = bos_1.corr().round(2) sns.heatmap(data=correlation_matrix, annot=True) The correlation coefficient ranges from -1 to 1. If the value is close to 1, it means that there is a strong positive correlation between the two variables. If it is close to -1, the variables have a strong negative correlation. We prefer to use features with high correlation (whether positive or negative) with our target feature PRICE, to fit to the model. The feature RM has a strong positive correlation with PRICE (0.7) where as LSTAT has a high negative correlation (-0.74). We will draw a scatterplot of RM and LSTAT against PRICE to better visualise the correlation. plt.figure(figsize=(20, 5)) features = ['LSTAT', 'RM'] target = bos['PRICE'] for i, col in enumerate(features): plt.subplot(1, len(features) , i+1) x = bos[col] y = target plt.scatter(x, y,color='green', marker='o') plt.title("Variation in House prices") plt.xlabel(col) plt.ylabel('"House prices in $1000"') Also, an important point in selecting features for a linear regression model is to check for multi-co-linearity. The features RAD, TAX have a correlation of 0.91. These feature pairs are strongly correlated to each other. We should not select both these features together for training the model. Same goes for the features DIS and AGE which have a correlation of -0.75. Since we want to predict prices based on number of rooms only. We will only use RM feature to train on the model and PRICE feature will be our target. X_rooms = bos.RM y_price = bos.PRICE X_rooms = np.array(X_rooms).reshape(-1,1) y_price = np.array(y_price).reshape(-1,1) X_train_1, X_test_1, Y_train_1, Y_test_1 = train_test_split(X_rooms, y_price, test_size = 0.2, random_state=5) We have split the data set into training and test set. So, that we can make sure that our model performs well on unseen data. We fit our training data to LinearRegresion model and train it. We also calculate the RMSE (root mean square error) and R2 score to see how well our model performs. reg_1 = LinearRegression() reg_1.fit(X_train_1, Y_train_1) y_train_predict_1 = reg_1.predict(X_train_1) rmse = (np.sqrt(mean_squared_error(Y_train_1, y_train_predict_1))) r2 = round(reg_1.score(X_train_1, Y_train_1),2) print('RMSE is {}'.format(rmse)) print('R2 score is {}'.format(r2)) print("\n") We get : RMSE is 6.972277149440585 R2 score is 0.43 Our model has been trained. Now, we will use it on test data. reg_1 = LinearRegression() reg_1.fit(X_train_1, Y_train_1) y_train_predict_1 = reg_1.predict(X_train_1) rmse = (np.sqrt(mean_squared_error(Y_train_1, y_train_predict_1))) r2 = round(reg_1.score(X_train_1, Y_train_1),2) print('RMSE is {}'.format(rmse)) print('R2 score is {}'.format(r2)) print("\n") We get: Root Mean Squared Error: 4.895963186952216 R^2: 0.69 We can see that our model worked better on the test set. We will now plot or predictions: prediction_space = np.linspace(min(X_rooms), max(X_rooms)).reshape(-1,1) plt.scatter(X_rooms,y_price) plt.plot(prediction_space, reg_1.predict(prediction_space), color = 'black', linewidth = 3) plt.ylabel('value of house/1000($)') plt.xlabel('number of rooms') plt.show() GitHub Link: https://github.com/CodersArts2017/Jupyter-Notebooks/blob/master/bosten_data_analysis.ipynb
- Unsupervised Machine Learning: Classification of Iris data set
The Iris data set is the 'Hello world' in the field of data science. This data sets consists of 3 different types of irises’ (Setosa, Versicolour, and Virginica) petal and sepal length, stored in a 150x4 numpy.ndarray. The rows being the samples and the columns being: Sepal Length, Sepal Width, Petal Length and Petal Width. The data set is often used in data mining, classification and clustering examples and to test algorithms. First we will load the Iris data set from sklearn.datasets and then we will convert it into a dataframe using pandas so that we can easily work with it. We will use matplotlib and seaborn to visualise the data. from sklearn.datasets import load_iris import matplotlib.pyplot as plt import pandas as pd import numpy as np import seaborn as sns dataset=load_iris() data=pd.DataFrame(dataset['data'],columns=['Petal length','Petal Width','Sepal Length','Sepal Width']) data['Species']=dataset['target'] data['Species']=data['Species'].apply(lambda x: dataset['target_names'][x]) data.head() Now, we will explore the data to understand it better and to make it suitable to be fed to the machine learning algorithm. We will check for missing values in the data: data.isnull().sum() We see that there are no missing value in this data set. We will check the information about our DataFrame including the index dtype and columns, non-null values and memory usage, by callling the info( ) function. data.info() We can see that there are 150 total rows and there is no missing value. The type of each column is also specified. Now, we will look at the descriptive statistics of the data using the describe( ) function. data.describe() We will now make a pairplot using seaborn to visualize the relationship between the columns of the data frame for different species. sns.pairplot(data,hue='Species') We can see the range of petal length, petal width, sepal length and sepal width for the 3 species easily from the graph. Thus, we can determine to which species a new data point might belong to. We can also visualise our dataframe using a heatmap,a violin plot and a boxplot; as follows: Heatmap: plt.figure(figsize=(10,11)) sns.heatmap(data.corr(),annot=True) plt.plot() Violin plot: plt.figure(figsize=(12,10)) plt.subplot(2,2,1) sns.violinplot(x='Species',y='Sepal Length',data=data) plt.subplot(2,2,2) sns.violinplot(x='Species',y='Sepal Width',data=data) plt.subplot(2,2,3) sns.violinplot(x='Species',y='Petal length',data=data) plt.subplot(2,2,4) sns.violinplot(x='Species',y='Petal Width',data=data) Boxplot: plt.figure(figsize=(12,10)) plt.subplot(2,2,1) sns.boxplot(x='Species',y='Sepal Length',data=data) plt.subplot(2,2,2) sns.boxplot(x='Species',y='Sepal Width',data=data) plt.subplot(2,2,3) sns.boxplot(x='Species',y='Petal length',data=data) plt.subplot(2,2,4) sns.boxplot(x='Species',y='Petal Width',data=data) Now, we need to replace the values of species column with some numerical value so that it will be easier for the machine to understand. This process is called encoding. We will replace 'setosa' with '0', 'versicolor' with '1' and 'virginica' with '2'. from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(data['Species']) y =le.transform(data['Species']) y We can see that the species column have been encoded using LabelEncoder from preprocessing class of sklearn library. Now, our data is ready to be trained on different classification models. Here we will be training our data on DecisionTreeClassifier, SupportVectorClassifier, RandomForestClassifier and KNeighboursClassifiers, then we will determine which algorithm worked better. DecisionTreeClassifier from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import cross_val_score DT = DecisionTreeClassifier(random_state=0) score1=cross_val_score(DT, data[['Petal length','Petal Width','Sepal Length']], y, cv=10) print(score1.mean()) Output: 0.9466666666666667 SupportVectorClassifier from sklearn.svm import SVC svm_clf =SVC(gamma='auto') score2=cross_val_score(svm_clf, data[['Petal length','Petal Width','Sepal Length']], y, cv=10) print(score2.mean()) Output: 0.9533333333333334 RandomForestclassifier from sklearn.ensemble import RandomForestClassifier RFC = RandomForestClassifier(max_depth=2, random_state=0) score3=cross_val_score(RFC, data[['Petal length','Petal Width','Sepal Length']], y, cv=10) print(score3.mean()) Output: 0.9133333333333333 KNeighboursClassifiers from sklearn.neighbors import KNeighborsClassifier KNN = KNeighborsClassifier(n_neighbors=3) score4=cross_val_score(RFC, data[['Petal length','Petal Width','Sepal Length']], y, cv=10) print(score4.mean()) Output: 0.9133333333333333 The output of the above code snippets shows the accuracy of the model. The higher the accuracy the better the model at classifying correctly. We can see that SupportVectorClassifier was the best at classifying correctly followed by DecisionTreeClassifier and then by RandomForestClassifier and KNeighboursClassifiers both of which performed equally. We can't say that this is always true. Different algorithms work better in different situations. So we should always train our data on a number of algorithms and we should then select the best. GitHub link: https://github.com/CodersArts2017/Jupyter-Notebooks/raw/master/IRIS_CONTENT.ipynb
- Research Paper Implementation : Machine Translation for Academic Purposes.
ABSTRACT Due to the globalization trend and knowledge boost in the second millennium, multi-lingual translation has become a noteworthy issue. For the purposes of learning knowledge in academic fields, Machine Translation (MT) should be noticed not only academically but also practically. MT should be informed to the translating learners because it is a valuable approach to apply by professional translators for diverse professional fields. For learning translating skills and finding a way to learn and teach through bi-lingual/multilingual translating functions in software, machine translation is an ideal approach that translation trainers, translation learners, and professional translators should be familiar with. In fact, theories for machine translation and computer assistance had been highly valued by many scholars. (e.g., Hutchines, 2003; Thriveni, 2002) Based on MIT’s Open Courseware into Chinese that Lee, Lin and Bonk (2007) have introduced, this paper demonstrates how MT can be efficiently applied as a superior way of teaching and learning. This article predicts the translated courses utilizing MT for residents of global village should emerge and be provided soon in industrialized nations and it exhibits an overview about what the current developmental status of MT is, why the MT should be fully applied for academic purpose, such as translating a textbook or teaching and learning a course, and what types of software can be successfully applied. It implies MT should be promoted in Taiwan because its functions of clearly translating the key-words and leading the basic learners to a certain professional field can be proved in MIT. Keywords Machine Translation, Computational Linguistics, Bi-lingual/Multilingual Translating, Open Courseware. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Research Paper Implementation : Autoencoders, Unsupervised Learning, and Deep Architectures.
ABSTRACT Autoencoders play a fundamental role in unsupervised learning and in deep architectures for transfer learning and other tasks. In spite of their fundamental role, only linear autoencoders over the real numbers have been solved analytically. Here we present a general mathematical framework for the study of both linear and non-linear autoencoders. The framework allows one to derive an analytical treatment for the most non-linear autoencoder, the Boolean autoencoder. Learning in the Boolean autoencoder is equivalent to a clustering problem that can be solved in polynomial time when the number of clusters is small and becomes NP complete when the number of clusters is large. The framework sheds light on the different kinds of autoencoders, their learning complexity, their horizontal and vertical composability in deep architectures, their critical points, and their fundamental connections to clustering, Hebbian learning, and information theory. KEYWORDS autoencoders, unsupervised learning, compression, clustering, principal component analysis, boolean, complexity, deep architectures, hebbian learning, information theory. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Research Paper Implementation : Sequence to Sequence Learning with Neural Networks.
ABSTRACT Deep Neural Networks (DNNs) are powerful models that have achieved excellent performance on difficult learning tasks. Although DNNs work well whenever large labelled training sets are available, they cannot be used to map sequences to sequences. In this paper, we present a general end-to-end approach to sequence learning that makes minimal assumptions on the sequence structure. Our method uses a multilayered Long Short-Term Memory (LSTM) to map the input sequence to a vector of a fixed dimensionality, and then another deep LSTM to decode the target sequence from the vector. Our main result is that on an English to French translation task from the WMT-14 dataset, the translations produced by the LSTM achieve a BLEU score of 34.8 on the entire test set, where the LSTM’s BLEU score was penalized on out-of-vocabulary words. Additionally, the LSTM did not have difficulty on long sentences. For comparison, a phrase-based SMT system achieves a BLEU score of 33.3 on the same dataset. When we used the LSTM to rerank the 1000 hypotheses produced by the aforementioned SMT system, its BLEU score increases to 36.5, which is close to the previous state of the art. The LSTM also learned sensible phrase and sentence representations that are sensitive to word order and are relatively invariant to the active and the passive voice. Finally, we found that reversing the order of the words in all source sentences (but not target sentences) improved the LSTM’s performance markedly, because doing so introduced many short term dependencies between the source and the target sentence which made the optimisation problem easier. To download full research paper click on the link below. If you need implementation of this research paper or any of its variants, feel free contact us on contact@codersarts.com.
- Predicting Cab Supply and Demand(Cab Booking System)
About the project: Cab booking system is the process where renting a cab is automated through an app throughout a city. Using this app, people can book a cab from one location to another location. Being a cab booking app company, exploiting the understanding of cab supply and demand could increase the efficiency of their service and enhance the user experience by minimizing waiting time. Objective of this project is to combine historical usage patterns along with open data sources like weather data to forecast cab booking demand in a city. You will be provided with an hourly renting data span of two years. Data is randomly divided into train and test sets. You must predict the total count of cabs booked in each hour covered by the test set, using the information available prior to the booking period. You need to append the train_label dataset to train.csv as the ‘Total_booking’ column. Please find the descriptions of the columns present in the dataset below. datetime - hourly date + timestamp season - spring, summer, autumn, winter holiday - whether the day is considered a holiday workingday - whether the day is neither a weekend nor holiday weather - Clear , Cloudy, Light Rain, Heavy temp - temperature in Celsius atemp - "feels like" temperature in Celsius humidity - relative humidity windspeed - wind speed Total_booking - number of total booking DATASET The recommended datasets will be shared. You can download them from the LMS TASKS Following are the tasks, which need to be developed while executing the project: Task 1: 1. Visualize data using different visualizations to generate interesting insights. 2. Outlier Analysis 3. Missing value analysis 4. Visualizing Total_booking Vs other features to generate insights 5. Correlation Analysis Task 2: 1. Feature Engineering 2. Grid search 3. Regression Analysis 4. Ensemble Model Solution: Task 1: import pandas as pd # Here, I have append the rows of train dataset and test dataset df11=pd.read_csv('C:/Project_1_dataset/Dataset/train.csv') df111=pd.read_csv('C:/Project_1_dataset/Dataset/test.csv') df1=df11.append(df111,ignore_index=True) # Here, I have append the rows of train_label dataset and test_label dataset df22=pd.read_csv('C:/Project_1_dataset/Dataset/train_label.csv', header=None, names=['Total_Booking']) df222=pd.read_csv('C:/Project_1_dataset/Dataset/test_label.csv', header=None, names=['Total_Booking']) df2=df22.append(df222,ignore_index=True) # Here, I have Concatenate the columns of df1 and df2 dataset to get complete dataset. df = pd.concat([df1, df2], axis=1) df1=df you can change the path and add your own path where you can add these train and test datasets. # here, I have drop the duplicates rows from the dataset df. df=df.drop_duplicates() df Identifying Missing Values # Here, I have checked the Missing value in the dataset df.isnull().sum() Output: datetime 0 season 0 holiday 0 workingday 0 weather 0 temp 0 atemp 0 humidity 0 windspeed 0 Total_Booking 0 dtype: int64 # Here, I have checked the datatype of the given Columns. df.dtypes Output: datetime object season object holiday int64 workingday int64 weather object temp float64 atemp float64 humidity int64 windspeed float64 Total_Booking int64 dtype: object Outliers Analysis #Here, I have checked the outliers in the windspeed column through the boxplot graph. import seaborn as sns sns.boxplot(x=df['windspeed']) #Here, I have checked the outliers in the Humidity column through the boxplot graph. import seaborn as sns sns.boxplot(x=df['humidity']) As like above, you can get all outliers of each dataset columns: # Here, I have checked the outliers in the windspeed vs Total_Booking column through the scatter graph. import matplotlib.pyplot as plt import matplotlib fig, ax = plt.subplots(figsize=(16,8)) ax.scatter(df['windspeed'], df['Total_Booking']) ax.set_xlabel('Wind Speed') ax.set_ylabel('Total Booking') plt.show() Output: # Here, I am finding the zscore values of the numerical columns of the dataset df. from scipy import stats import numpy as np z = np.abs(stats.zscore(df[['windspeed','temp','atemp','humidity','Total_Booking']])) print(z) Output: [[0.5142603 0.24503701 0.24839078 0.78535767 1.7248125 ] [0.75963759 1.08700912 1.14227927 0.88928536 1.03002161] [1.12729319 1.85989326 2.07630932 0.61766615 0.29024652] ... [0.8819159 0.17594904 0.10975464 0.14999154 0.17983232] [0.46560752 0.38644207 0.28853234 1.66874304 0.89752458] [0.5142603 1.29750214 1.32105696 0.21375537 0.1790138 ]] # Here, I have checked where thresold is greater than 3. threshold = 3 print(np.where(z > 3)) # Here, I have drop the rows where zscore is less than 3 to remove the outliers of the dataset df df = df[(z < 3).all(axis=1)] # After removing the outliers, The dataset df is : df Output: # Here, You have to see in the boxplot graph that maximum outliers are remove from the windspeed column. Only three left import seaborn as sns sns.boxplot(x=df['windspeed']) Output: As like above, you can remove all outliers from other columns. Visualize data using different visualizations to generate interesting insights. # Show value counts for a weather Column of dataset df_o: import matplotlib.pyplot as plt import seaborn as sbn sbn.countplot(x='weather',data=df) plt.xticks(rotation=90) plt.show() Output: # Show value counts for a season Column and weather Column of dataset df_o: import seaborn as sbn sbn.countplot(x='season',data=df,hue='weather') plt.show() Output: # Show value counts for a season Column and Holiday Column of dataset df_o where 0 value represent No Holiday and 1 value represent Holiday: import seaborn as sbn sbn.countplot(x='season',data=df,hue='holiday') plt.show() Output: # Show value counts for a season Column and WorkingDay Column of dataset df_o where 0 value represent No WorkingDay and 1 value represent WorkingDay: import seaborn as sbn sbn.countplot(x='season',data=df,hue='workingday') plt.show() Output: # Here, I have draw the Pie chart between HoliDay, WorkingDay And No Holiday No Workingday to check the status in percentile. Not_Holiday_Not_workingday=df[(df.holiday==0) & (df.workingday==0)].shape[0] print('No working and No Holiday = ', Not_Holiday_Not_workingday) Holiday=df[(df.holiday==1)].shape[0] print('Total HoliDay = ', Holiday) WorkingDay=df[(df.workingday==1)].shape[0] print('Total Working Day = ', WorkingDay) plt.pie(x=[Not_Holiday_Not_workingday,WorkingDay,Holiday],labels=['No Holiday & No workingday','WorkingDay','Holiday'],explode=(.1,.1,.1),colors=['g','r','b'],autopct='%.2f',wedgeprops={'edgecolor':'k'}) plt.show() Output: Fetch specified value from dataset column value #Here, I have fetch the Months from the datetime column df1['booking_month'] = pd.to_datetime(df1.datetime, format='%m/%d/%Y %H:%M').dt.month_name() #Here, I have fetch the Days from the datetime column df1['booking_day'] = pd.to_datetime(df1.datetime, format='%m/%d/%Y %H:%M').dt.day_name() #The time of departure is in 24 hours format(22:20), we would like to bin it to get insights. #Here, I have decided to group hours into 4 bins. [0–5], [6–11], [12–17] and [18–23] are the 4 bins. df1['timing'] = pd.to_datetime(df1.datetime, format='%m/%d/%Y %H:%M') a = df1.assign(dept_session=pd.cut(df1.timing.dt.hour,[0,6,12,18,24],labels=['Night','Morning','Afternoon','Evening'])) df1['booking_session'] = a['dept_session'] #Here, I have fetch the Year from the datetime column l2=[] for i in range(0,df1.shape[0]): l2.append(df1.datetime[i][df1.datetime[i].rindex('/')+1:df1.datetime[i].rindex('/')+5]) df1['year']=pd.DataFrame(l2,columns=['year']) df1 Output: # Show value counts for a Months Column of dataset df. import matplotlib.pyplot as plt import seaborn as sbn sbn.countplot(x='booking_month',data=df1) plt.xticks(rotation=90) plt.show() Output: # Show value counts for a Day Column of dataset df. import matplotlib.pyplot as plt import seaborn as sbn sbn.countplot(x='booking_day',data=df1) plt.xticks(rotation=90) plt.show() Output: # Show value counts for a Year Column and booking_session column of dataset df. import matplotlib.pyplot as plt import seaborn as sbn sbn.countplot(x='year',data=df1,hue='booking_session') plt.xticks(rotation=90) plt.show() Output: Visualizing Total_booking Vs other features to generate insights # Show the Line Plot Between booking_Month vs Total_Booking column import matplotlib.pyplot as plt import seaborn as sbn sbn.lineplot(x="booking_month", y="Total_Booking", data=df) plt.xticks(rotation=90) Output: # Show the Line Plot Between booking_day vs Total_Booking column. import matplotlib.pyplot as plt import seaborn as sbn sbn.lineplot(x="booking_day", y="Total_Booking", data=df) plt.xticks(rotation=90) Output: Correlation Analysis: df.corr('spearman') Task 2 : Feature Engineering import pandas as pd # Here, I have append the rows of train dataset and test dataset df11=pd.read_csv('C:/Project_1_dataset/Dataset/train.csv') df111=pd.read_csv('C:/Project_1_dataset/Dataset/test.csv') df1=df11.append(df111,ignore_index=True) # Here, I have append the rows of train_label dataset and test_label dataset df22=pd.read_csv('C:/Project_1_dataset/Dataset/train_label.csv', header=None, names=['Total_Booking']) df222=pd.read_csv('C:/Project_1_dataset/Dataset/test_label.csv', header=None, names=['Total_Booking']) df2=df22.append(df222,ignore_index=True) # Here, I have Concatenate the columns of df1 and df2 dataset to get complete dataset. df = pd.concat([df1, df2], axis=1) df Output: # Here, I have checked the datatype of the given Columns. df.dtypes Output: datetime object season object holiday int64 workingday int64 weather object temp float64 atemp float64 humidity int64 windspeed float64 Total_Booking int64 dtype: object Contact us to get a complete solution or need any other related machine learning project help, then you can contact us at below contact detail: contact@codersarts.com
- Classification of malignant and benign cells.
Given a data set containing features of cells, we need to determine whether a cell is malignant or benign. This comes under classification. It is a type of supervised-learning. It categorises the data into different classes and also predicts the class of a data passed as an input. We will use sklearn module as it provides a range of supervised and unsupervised learning algorithms. It is designed to interoperate with with the Python numerical and scientific libraries NumPy and SciPy. First, we import various libraries that we will need along with the data from sklearn.datasets. import sklearn import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.datasets import load_breast_cancer from sklearn.metrics import roc_curve, auc from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline import seaborn as sns from sklearn.preprocessing import StandardScaler We also imported pandas to deal with dataframes, NumPy to work with arrays which also supports various mathematical functions, maplotlib and seaborn for data visualisation. Now, we need to load the data and convert it into a dataframe as it is easier to manipulate and analyse the data. data = load_breast_cancer() a=np.c_[data.data, data.target] columns = np.append(data.feature_names, ["target"]) df_cancer=pd.DataFrame(a,columns=columns) df_cancer.head() The head() function shows top 5 rows of our dataframe, we used it to see if the data has been correctly converted into a dataframe with right column names and to get a better understanding of our data. The dataframe looks like this: There are 10 different cell nuclei parameters: Radius: Distance from the centre to the perimeter. Perimeter: The value of core tumour. The total distance between the points give perimeter. Area: Area of cancer cells. Smoothness: This gives the local variation in the radius lengths. The smoothness is given by difference of radial length and mean lengths of the lines around it. Compactness: It is value of estimation of perimeter and area,it is given by (perimeter^2 / area - 1.0). Concavity: Severity of concave points is given . Smaller chords encapsulate small concavities better. This feature is affected by length Concave points: The concavity measures magnitude of contour concavities while concave points measures the number of concave points Symmetry: The longest chord is taken as major axis.The length difference between the line perpendicular to the major axis is taken. This is known as the symmetry. Fractal dimension: It is a measure of non linear growth. As the ruler used to measure the perimeter increases, the precision decreases and hence the perimeter decreases. This data is plotted using log scale and the downward slope gives us an approximation of fractal dimension Texture: Standard derivation of the Gray scale area. This is helpful to find out the variation. Higher value of all the shape features imply irregular contour which in turn implies a malignant cell. The worst and error values are taken because only few malignant cells maybe present in an given sample.To better correlate malignant cells, these values are taken. The surgery depends on the size of tumour hence worst values are necessary. The target value is zero for malignant and one for benign. We divide the data into two classes: Malignant and Benign. Malignant=df_cancer[df_cancer['target'] ==0] Benign=df_cancer[df_cancer['target'] ==1] We divide the feature names into three categories: mean, error and worst. mean_features= ['mean radius', 'mean texture', 'mean perimeter', 'mean area', 'mean smoothness', 'mean compactness', 'mean concavity', 'mean concave points', 'mean symmetry', 'mean fractal dimension'] error_features=['radius error', 'texture error', 'perimeter error', 'area error', 'smoothness error', 'compactness error', 'concavity error', 'concave points error', 'symmetry error', 'fractal dimension error'] worst_features=['worst radius', 'worst texture', 'worst perimeter', 'worst area', 'worst smoothness', 'worst compactness', 'worst concavity', 'worst concave points', 'worst symmetry', 'worst fractal dimension'] We will create a function to plot histograms with 10 subplots. bins = 20 #Number of bins is set to 20, bins are specified to divide the range of values into intervals def histogram(features): plt.figure(figsize=(10,15)) for i, feature in enumerate(features): plt.subplot(5, 2, i+1) #subplot function: the number of rows are given as 5 and number of columns as 2, the value i+1 gives the subplot number, subplot numbers start with 1 sns.distplot(Malignant[feature], bins=bins, color='red', label='Malignant'); sns.distplot(Benign[feature], bins=bins, color='green', label='Benign'); plt.title(str(' Density Plot of: ')+str(feature)) plt.xlabel('X variable') plt.ylabel('Density Function') plt.legend(loc='upper right') plt.tight_layout() plt.show() We call the function for mean, error and worst features of the malignant and benign cells. histogram(mean_features) histogram(error_features) histogram(worst_features) We will now write a function to plot a ROC (Receiver Operating Characteristics). It is a measure of performance for classification problems at various threshold points. This curve is plotted True positive rate and False positive rate. Larger the area under the curve, better the model at distinguishing between two classes which in our case are malignant and benign. def ROC_curve(X,Y,string): X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.4) # Splitting the data for training and testing in 60/40 ratio model=LogisticRegression(solver='liblinear') #Using logistic regression model model.fit(X_train,y_train) probability=model.predict_proba(X_test) #Predicting probability fpr, tpr, thresholds = roc_curve(y_test, probability[:,1]) #False positive rate, True Positive Rate and Threshold is returned using this function roc_auc = auc(fpr, tpr) #The area under the curve is given by this function plt.figure() plt.plot(fpr, tpr, lw=1, color='green', label=f'AUC = {roc_auc:.3f}') plt.plot([0,1],[0,1],linestyle='--',label='Baseline') #Plotting the baseline plt.title(string) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate ') plt.legend() plt.show() ROC_curve(df_cancer[mean_features],df_cancer['target'],'ROC for mean features ') ROC_curve(df_cancer[error_features],df_cancer['target'],'ROC for error features') ROC_curve(df_cancer[worst_features],df_cancer['target'],'ROC for worst features') An excellent model has area under the curve near to 1 which means it has good measure of separability. In the above ROC curves we can see that mean and worst features show high accuracy. Therefore, we will not take the error features in consideration. Also, in the histograms plotted above we see that there is an overlapping between the features of malignant and benign cells. In order to make our model to distinguish better we need to select features with the least overlapping values. The top 5 features according to this are: worst area worst perimeter worst radius mean concave points mean concavity We will save these feature in a list called imp_features: imp_features=['worst area','worst perimeter','worst radius','mean concave points','mean concavity'] The mean of all the instances of all features for both Benign and Malignant classes are: m_feature_space=Malignant.mean(axis=0) b_feature_space=Benign.mean(axis=0) Now we, concatenate the two dataframes one with Benign and one with Malignant and calculate the mean between the values corresponding to the same features. z=pd.concat([m_feature_space,b_feature_space],axis=1) analysis_point=z.mean(axis=1) analysis_point.head() #Analysis point The output is: mean radius 14.804677 mean texture 19.759834 mean perimeter 96.720392 mean area 720.583306 mean smoothness 0.097688 dtype: float64 Creating X and Y, where X has all the features and Y contains target: X=df_cancer.drop(['target'],axis=1) Y=df_cancer['target'] Now, our data has been preprocessed and is ready to be trained. But before that, since we have an imbalanced data set due to only a few number of malignant cells, we will use the SMOTE (Synthetic Minority Oversampling TEchnique) from imbalanced-learn module. A problem with imbalanced classification is that there are too few examples of the minority class for a model to effectively learn the decision boundary. This technique will create new examples from the minority class (i.e. malignant cells). SMOTE works by selecting examples that are close in the feature space, drawing a line between the examples in the feature space and drawing a new sample at a point along that line. We will split our data into training and test set and then we will build a pipeline from the imblearn library as it can also include oversampling technique (SMOTE in this case). Using this pipeline we will implement StandardScaler,SMOTE, and DecisionTreeClassifier on our data. Also, we will use GridSearch for the hyper-parameter search of the features max_depth and min_leaf for DecisionTreeClassifier. The program code is given below: from imblearn.over_sampling import SMOTE from imblearn.pipeline import Pipeline max_depth = list(range(1,24)) min_leaf=list(range(1,20)) params = [{'classifier__max_depth':max_depth,'classifier__min_samples_leaf':min_leaf}] #Defining parameters for the grid search X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.4) pipe=Pipeline([('sc',StandardScaler()),('smt',SMOTE()),('classifier',DecisionTreeClassifier(random_state=0,min_samples_split=6,max_features=10))]) #Creating a pipeline grid_search_cv = GridSearchCV(pipe,params,scoring='accuracy',refit=True, verbose=1,cv=5) #Grid Search function which will put different combinations of the parameters grid_search_cv.fit(X_train,y_train) Specified a value for max_features, max_features gives us how many features should be taken a time when taking the best split, if we have too many features it will have computationally heavy. Taking the value of 10, as we have 30 features. The min_samples_split is used to control overfitting, the ideal value for it should be between 1 to 40.If the value is too low we see overfitting. Decison Trees don't generally require scaling but we used it here to compare the decision tree with SVM. There is no drastic change in decision trees with scaling. The different class sizes might result in bias, although the difference is not very huge, it still is better to have a balanced class data set. we applied oversampling using the smote function to solve this problem. The max_depth for a decision tree should be equal to or less than the square-root of the instances for most optimum case, hence we choose the range of 1 to 24. If the depth is too large we see over-fitting and if too low we see under-fitting. The min_samples_leaf gives the minimum samples to become a leaf node. Too low value will give over-fitting and too large value will make it computationally expensive, hence we take the range to be 1 to 20. The output is as follows: GridSearchCV(cv=5, error_score=nan, estimator=Pipeline(memory=None, steps=[('sc', StandardScaler(copy=True, with_mean=True, with_std=True)), ('smt', SMOTE(k_neighbors=5, kind='deprecated', m_neighbors='deprecated', n_jobs=1, out_step='deprecated', random_state=None, ratio=None, sampling_strategy='auto', svm_estimator='deprecated')), ('classifier', DecisionTreeClassi... presort='deprecated', random_state=0, splitter='best'))], verbose=False), iid='deprecated', n_jobs=None, param_grid=[{'classifier__max_depth': [1,2,3,4,5,6,7,8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,23], 'classifier__min_samples_leaf': [1, 2, 3, 4, 5, 6,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}], pre_dispatch='2*n_jobs', refit=True, return_train_score=False, scoring='accuracy', verbose=1) Finding the best model from grid search model=grid_search_cv.best_estimator_ We will check the accuracy of the model: from sklearn.metrics import accuracy_score model.fit(X_train,y_train) #Fitting the model test_pred = model.predict(X_test) print(accuracy_score(y_test, test_pred)) #accuracy score function, to print the accuracy of the model y_test.value_counts() The output is: 0.9429824561403509 1.0 136 0.0 92 Name: target, dtype: int64 We will define a variable params to save the parameters of the model: params=model.get_params() Now, we will produce the confusion matrix and classification report. from sklearn.metrics import confusion_matrix from sklearn.metrics import classification_report matrix=np.array(confusion_matrix(y_test,test_pred,labels=[0,1])) #Creating confusion matrix pd.DataFrame(matrix,index=['Cancer','No Cancer'],columns=['Predicted_Cancer','Predicted_No_Cancer']) #Labelling the matrix print(classification_report(y_test, test_pred)) #The classification report gives precision,recall and f1 score Failing to detect a sample which has cancer means we look at the intersection of cancer and predicted no cancer. The number is 4 out of 91. When a person has cancer and it is detected as no cancer, the chance of happening so is 0.043. The weakness of the classifier is the computational overhead. The strength of the classifier shows good accuracy and chances of detecting a sample as no cancer while it is cancer is not very much which is desired in this case. We will now plot the decision tree and train our data on it. We will plot the scatter plots of imp_features. from sklearn import tree plt.figure(figsize=(40,40)) tree.plot_tree(model['classifier']) #function used to plot decision tree Output: [Text(1116.0, 1993.2, 'X[7] <= 0.128\ngini = 0.5\nsamples = 440\nvalue = [220, 220]'), Text(558.0, 1630.8000000000002, 'X[23] <= 0.083\ngini = 0.182\nsamples = 227\nvalue = [23, 204]'), Text(279.0, 1268.4, 'X[1] <= 0.488\ngini = 0.057\nsamples = 205\nvalue = [6, 199]'), Text(139.5, 906.0, 'gini = 0.0\nsamples = 163\nvalue = [0, 163]'), Text(418.5, 906.0, 'X[27] <= -0.302\ngini = 0.245\nsamples = 42\nvalue = [6, 36]'), Text(279.0, 543.5999999999999, 'X[17] <= -0.261\ngini = 0.062\nsamples = 31\nvalue = [1, 30]'), Text(139.5, 181.19999999999982, 'gini = 0.0\nsamples = 21\nvalue = [0, 21]'), Text(418.5, 181.19999999999982, 'gini = 0.18\nsamples = 10\nvalue = [1, 9]'), Text(558.0, 543.5999999999999, 'gini = 0.496\nsamples = 11\nvalue = [5, 6]'), Text(837.0, 1268.4, 'X[24] <= -0.355\ngini = 0.351\nsamples = 22\nvalue = [17, 5]'), Text(697.5, 906.0, 'gini = 0.48\nsamples = 10\nvalue = [6, 4]'), Text(976.5, 906.0, 'gini = 0.153\nsamples = 12\nvalue = [11, 1]'), Text(1674.0, 1630.8000000000002, 'X[21] <= -0.321\ngini = 0.139\nsamples = 213\nvalue = [197, 16]'), Text(1395.0, 1268.4, 'X[20] <= 0.266\ngini = 0.493\nsamples = 34\nvalue = [19, 15]'), Text(1255.5, 906.0, 'gini = 0.117\nsamples = 16\nvalue = [1, 15]'), Text(1534.5, 906.0, 'gini = 0.0\nsamples = 18\nvalue = [18, 0]'), Text(1953.0, 1268.4, 'X[0] <= -0.227\ngini = 0.011\nsamples = 179\nvalue = [178, 1]'), Text(1813.5, 906.0, 'gini = 0.18\nsamples = 10\nvalue = [9, 1]'), Text(2092.5, 906.0, 'gini = 0.0\nsamples = 169\nvalue = [169, 0]')] It is a tree flowchart, each observation splits according to some feature. There are two ways to go from each node if the condition is true it goes one way and if false it goes the other way. The first line(here X7),gives the feature and compares it to some value. The second row gives us the value of gini index at every node. Gini index is computed mathematically. Gini index=0 means the node is perfect and we get definite class. The sample row gives us the number of samples being considered. The value row in each node gives us the number of samples in each class. In all the nodes the features are considered but the feature which gives best gini index is chosen. clf=DecisionTreeClassifier(random_state=0,min_samples_leaf=2,min_impurity_split=6,max_depth=11) #Replicating the decision tree classifier as our classifier had max_features as 10 which can not be applied here, as the features taken are 2 k=1 plt.figure(figsize=(20,40)) for i in range(0,4): for j in range(1,5): inp=pd.concat([X[imp_features[i]],X[imp_features[j]]],axis=1) #Taking data from two features clf.fit(inp,Y) plt.subplot(4, 4, k) k=k+1 plt.scatter(X[imp_features[i]], X[imp_features[j]], c=Y, s=30) #Creating scatter plot ax = plt.gca() xlim = ax.get_xlim() ylim = ax.get_ylim() xx, yy = np.meshgrid(np.linspace(xlim[0], xlim[1], 50),np.linspace(ylim[0], ylim[1], 50)) #Creating a meshgrid of data points Z = Z.reshape(xx.shape) plt.contourf(xx, yy, Z,alpha=0.5, cmap=plt.cm.Paired, linestyles=['--','+','--']) plt.title(str(imp_features[i])+' & '+str(imp_features[j])) We will write a code to print the important features according to the grid search and then compare it with the important features selected by us at the beginning of the program. feat_importances = pd.Series(model['classifier'].feature_importances_, index=X.columns) #function to save the most important features feat_importances = feat_importances.nlargest(5) #as we need only 5 features nlargest() is used feat_importances.plot(kind='barh',figsize=(12,8),title='Most Important Features') #plotting bar graph imp_features=list(feat_importances.index) print(feat_importances) Output: mean concave points 0.756231 worst area 0.138760 worst texture 0.072523 worst radius 0.019084 mean texture 0.010388 dtype: float64 As we can see that the important features predicted by us and the grid search are the same. Hence, it will be safe to say that the program is running as expected. Now, let's train our data using SVM (Support Vector Machine). It is a supervised machine learning algorithm which can be used for classification or regression problems. It uses a technique called the kernel trick to transform your data and then based on these transformations it finds an optimal boundary between the possible outputs. Firstly, we will use GridSearch to select the best values of C and gamma. Also, we will use a pipeline to implement StandardScaler, SMOTE, and SVM Classifier on our data. from sklearn.svm import SVC from imblearn.over_sampling import SMOTE from imblearn.pipeline import Pipeline c=[0.01,0.1,1,10] gamma=[0.01,0.1,1,10] params = [{'classifier__C':c,'classifier__gamma':gamma}] #Setting the parameters X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.4) pipe=Pipeline([('sc',StandardScaler()),('smt',SMOTE()),('classifier',SVC(kernel='rbf'))]) #Creating the pipeline grid_search_cv = GridSearchCV(pipe,params,refit=True, verbose=1,cv=5) grid_search_cv.fit(X_train,y_train) Ouput: GridSearchCV(cv=5, error_score=nan, estimator=Pipeline(memory=None, steps=[('sc', StandardScaler(copy=True, with_mean=True, with_std=True)), ('smt', SMOTE(k_neighbors=5, kind='deprecated', m_neighbors='deprecated', n_jobs=1, out_step='deprecated', random_state=None, ratio=None, sampling_strategy='auto', svm_estimator='deprecated')), ('classifier', SVC(C=1.0, break_ti... decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False))], verbose=False), iid='deprecated', n_jobs=None, param_grid=[{'classifier__C': [0.01, 0.1, 1, 10], 'classifier__gamma': [0.01, 0.1, 1, 10]}], pre_dispatch='2*n_jobs', refit=True, return_train_score=False, scoring=None, verbose=1) In the output, both the C value and gamma are in the range of 10. C is a regularization parameter so we choose the range as 0.01, 0.1,1 and 10. Similarly for gamma we choose 0.01, 0.1, 1 and 10. Value less than 0.01 would have been too low and value more than 10 would have been too high. Hence, we choose this range. Gridsearch CV gives the best combination of these two features. We will check the accuracy of the model: svc=grid_search_cv.best_estimator_ #Saving the best estimator svc.fit(X_train,y_train) test_pred = svc.predict(X_test) print(accuracy_score(y_test, test_pred)) Output: 0.9868421052631579 We will create a confusion matrix and classification report for this model as well. from sklearn.metrics import confusion_matrix from sklearn.metrics import classification_report matrix=np.array(confusion_matrix(y_test,test_pred,labels=[0,1])) pd.DataFrame(matrix,index=['Cancer','No Cancer'],columns=['Predicted_Cancer','Predicted_No_Cancer']) print(classification_report(y_test, test_pred)) People that have cancer but are predicted with no cancer are 3 out of 91 in this model, which is better than the decision tree classifier. The chances of failing to detect cancer is 0.03. The advantage of support vector classifier is it is relatively more efficient. The disadvantage is we need to scale the data before using it as support vector machine can show bias towards a feature if the data is not scaled. Visualising the result: k=1 plt.figure(figsize=(20,40)) for i in range(0,4): for j in range(1,5): inp=pd.concat([X[imp_features[i]],X[imp_features[j]]],axis=1) s=svc['classifier'].fit(inp,Y) decision_function = svc['classifier'].decision_function(inp) plt.subplot(4, 4, k) k=k+1 plt.scatter(X[imp_features[i]], X[imp_features[j]], c=Y, s=30, cmap=plt.cm.Paired) ax = plt.gca() xlim = ax.get_xlim() ylim = ax.get_ylim() xx, yy = np.meshgrid(np.linspace(xlim[0], xlim[1], 50),np.linspace(ylim[0], ylim[1], 50)) xy = np.vstack([xx.ravel(), yy.ravel()]).T Z = svc['classifier'].decision_function(xy).reshape(xx.shape) Z = Z.reshape(xx.shape) plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, levels=[-1, 0, 1], alpha=0.5,linestyles=['--', '-', '--']) ax.scatter(s.support_vectors_[:, 0], s.support_vectors_[:, 1], s=10,linewidth=1, facecolors='none', edgecolors='k') #Showing support vectors plt.title(str(imp_features[i])+' & '+str(imp_features[j])) The model is not showing over-fitting as it is giving good accuracy in testing data as well. Over-fitting occurs when the accuracy in training data is very high but in test data is low.
- Working With Weather Database
Step 1 – Import the Weather Database into your SQL Server Management Studio 1. Open SQL Server Management Studio. Note: a recorded copy of the following steps can be found at https://njit.webex.com/mw3300/mywebex/nbrshared.do 2. Right click on database in the navigation window and select New Database 3. When the screen below appears, enter Weather as shown in the circle below and press the OK button 4. Next right click the Weather database and select Tasks and then Import Data as shown below 5. The import wizard will start and the following window will open. Click the NEXT button 6. When the window below opens, select FLAT FILE as the data source and the window will expand to have the following additional selections 7. Click the Browse button and navigate to where you unzipped the zip file in step 2 and select the AQS_Sires.txt file as shown below 8. Select the COLUMNS option in the left hand navigation tab to make sure the columns have been properly identified. The screen should look like the following 9. Next select the ADVANCED option and the following screen will appear. Once it does, you need to change the OUTPUT COLUMN WIDTH to 255 by click on the original width (shown as 50) and overwriting it with 255. This must be done for the Met_Site_Type, Met_Site_Direction, Owning_Agency, Local_Site_Name, Address, City Name, CBSA_Name and Tribe_Name and then click the NEXT button 10. Next, change the Destination to SQL Server Native Client and make sure the Server and Authentication information is correct and then hit NEXT 11. Hit NEXT when the following window appears 12. Hit the FINISH button when the following windows appears 13. Click FINISH when the following screen appears 14. Hit FINISH and the following screen will show the progress and have the below information when it finishes Database Description 1. The database contains 2 tables a. Aqs_sites – contains information regarding the sites where the temperature information in the Temperature table was collected. All the column should be self explanatory. The linkage between the 2 tables use the State_Code, County_Code and Site_Number columns b. Temperature – contains the daily temperature information collected at the site for 2 decades. The important columns for the assignment are: i. State_Code, County_Code and Site_Number are used to join to the aqs_sites table ii. Date_Local – The date that the sample was collected iii. Average_Temp – The average temperature for that particular date iv. Daily_High_Temp – The highest temperature for the day v. All temperatures are in degrees Fahrenheit 2. Suggestion: Due to the large number of records in the database, your queries may take several minutes to execute. If your queries are taking a long time to run, I suggest you make a table containing a small subset of the data in the Temperature table to use for writing and debugging your queries. After they all execute successfully, you can change the queries to use the full Temperature table 3. Grading – You will receive separate grades for Part 3, Part 4 and Part 5 (if you complete Part 5 for the extra credit). Both parts 3 and 4 will be worth 100 points each and each question in the step will be worth a proportionate value (1/# of questions in the step) Parts 3 and 4 will make up 50% of the Project grade. The extra credit (Part 5) will be worth 15% extra. Creating Geospatial Data Your last concern is how long will it take to travel back home to visit friends and family after you move. Since the Weather database has latitude and longitude information, you have decided to convert this information into a new column with a GEOGRAPHY data type and populate the new column with a set command and one of the following formula (Depending on the data type for latitude and longitude) The example below is for when latitude and longitude are varchar. Use Weather go IF NOT EXISTS( SELECT * FROM sys.columns WHERE Name = N'GeoLocation' AND Object_ID = Object_ID(N'AQS_Sites')) BEGIN ALTER TABLE AQS_Sites ADD GeoLocation Geography NULL END go UPDATE aqs_sites SET GeoLocation = geography::STPointFromText('POINT(' + LONGITUDE + ' ' + [Latitude] + ')', 4326) where (LATITUDE is not null and Longitude is not null) and Longitude <> '0' and Longitude <>'' Submission 1 – Problems You are trying to decide where in the US to reside. The most important factor to you is temperature, you hate cold weather. Answer the following questions to help you make your decision. For all problems show all columns included in the examples. Note that the term temperature applies to the average daily temperature unless otherwise stated. 1. Determine the date range of the records in the Temperature table First Date Last Date 1986-01-01 2017-05-09 2. Find the minimum, maximum and average of the average temperature column for each state sorted by state name. State_Name Minimum Temp Maximum Temp Average Temp Alabama -4.662500 88.383333 59.328094 Alaska -43.875000 80.791667 29.146757 Arizona -99.000000 135.500000 67.039050 3. The results from question #2 show issues with the database. Obviously, a temperature of -99 degrees Fahrenheit in Arizona is not an accurate reading as most likely is 135.5 degrees. Write the queries to find all suspect temperatures (below -39o and above 105o). Sort your output by State Name and Average Temperature. State_Name state_code County_Code Site_Number average_Temp date_local Wisconsin 55 059 0002 -58.000000 2002-03-28 Washington 53 009 0013 -50.000000 2012-10-17 Texas 48 141 0050 106.041667 1991-07-28 Texas 48 141 0050 106.291667 1991-07-25 4. You noticed that the average temperatures become questionable below -39 o and above 125 o and that it is unreasonable to have temperatures over 105 o for state codes 30, 29, 37, 26, 18, 38. You also decide that you are only interested in living in the United States, not Canada or the US territories. Create a view that combines the data in the AQS_Sites and Temperature tables. The view should have the appropriate SQL to exclude the data above. You should use this view for all subsequent queries. My view returned 5,616,112 rows. The view includes the State_code, State_Name, County_Code, Site_Number, Make sure you include schema binding in your view for later problems. 5. Using the SQL RANK statement, rank the states by Average Temperature State_Name Minimum Temp Maximum Temp Average Temp State_rank Florida 35.96 88.00 73.348137 1 Texas -1.13 122.60 68.793757 2 Mississippi 22.23 91.16 68.493975 3 6. At this point, you’ve started to become annoyed at the amount of time each query is taking to run. You’ve heard that creating indexes can speed up queries. Create an index for your view. You are required to create an index with the unique and clustered parameters and the index will be on the State_Code, County_Code, Site_Number, Date_Local columns. Note: There are a couple of thousand duplicate rows that you must delete before you can create a unique index. I used the Rownumber parameter in a partition statement and deleted any row where the row number was greater than 1. To see if the indexing help, add print statements that write the start and stop time for the query in question #2 and run the query before and after the indexes are created. Note the differences in the times. Also make sure that the create index steps include a check to see if the index exists before trying to create it. The following is a sample of the output that should appear in the messages tab that you will need to calculate the difference in execution times before and after the indexes are created Begin Question 6 before Index Create At - 13:40:03 (777 row(s) affected) Complete Question 6 before Index Create At - 13:45:18 7. You’ve decided that you want to see the ranking of each high temperatures for each city in each state to see if that helps you decide where to live. Write a query that ranks (using the rank function) the states by averages temperature and then ranks the cities in each state. The ranking of the cities should restart at 1 when the query returns a new state. You also want to only show results for the 15 states with the highest average temperatures. Note: you will need to use multiple nested queries to get the State and City rankings, join them together and then apply a where clause to limit the state ranks shown. State_Rank State_Name State_City_Rank City_Name Average Temp 1 Florida 1 Not in a City 73.975759 1 Florida 2 Pinellas Park 72.878784 1 Florida 3 Valrico 71.729440 1 Florida 4 Saint Marks 69.594272 2 Texas 1 McKinney 76.662423 2 Texas 2 Mission 74.701098 8. You notice in the results that sites with Not in a City as the City Name are include but do not provide you useful information. Exclude these sites from all future answers. You can do this by either adding it to the where clause in the remaining queries or updating the view you created in #4 9. You’ve decided that the results in #8 provided too much information and you only want to 2 cities with the highest temperatures and group the results by state rank then city rank. State_Rank State_Name State_City_Rank City_Name Average Temp 1 Florida 1 Pinellas Park 72.878784 1 Florida 2 Valrico 71.729440 2 Louisiana 1 Baton Rouge 69.704466 2 Louisiana 2 Laplace (La Place) 68.115400 10. You decide you like the average temperature to be in the 80's. Pick 2 cities that meets this condition and calculate the average temperature by month for those 2 cities. You also decide to include a count of the number of records for each of the cities to make sure your comparisons are being made with comparable data for each city. Hint, use the datepart function to identify the month for your calculations. City_Name Month # of Records Average Temp Mission 1 620 60.794048 Mission 2 565 64.403861 Mission 3 588 69.727512 11. You assume that the temperatures follow a normal distribution and that the majority of the temperatures will fall within the 40% to 60% range of the cumulative distribution. Using the CUME_DIST function, show the temperatures for the same 3 cities that fall within the range. City_Name Avg_Temp Temp_Cume_Dist Mission 73.916667 0.400686891814539 Mission 73.956522 0.400829994275902 Mission 73.958333 0.402404121350887 12. You decide this is helpful, but too much information. You decide to write a query that shows the first temperature and the last temperature that fall within the 40% and 60% range for the 3 cities your focusing on. City_Name 40 Percentile Temp 60 Percentile Temp Mission 73.956522 80.083333 Pinellas Park 71.958333 78.125000 Tucson 63.750000 74.250000 13. You remember from your statistics classes that to get a smoother distribution of the temperatures and eliminate the small daily changes that you should use a moving average instead of the actual temperatures. Using the windowing within a ranking function to create a 4 day moving average, calculate the moving average for each day of the year. Hint: You will need to datepart to get the day of the year for your moving average. You moving average should use the 3 days prior and 1 day after for the moving average. City_Name Day of the Year Rolling_Avg_Temp Mission 1 59.022719 Mission 2 58.524868 Mission 3 58.812967 Mission 364 60.657749 Mission 365 61.726333 Mission 366 61.972514 We are also providing other database assignments help like, MongoDB, Oracle, PostgreSQL, MySQL, etc. If you need or looking for any database assignments or project help then you can please contact us at: contact@codersarts.com











