Keras and Tensorflow Pt III – Classification Example

This is a good simple example of a classification problem utilizing Keras and Tensorflow. In addition, I'm utilizing early stopping in an attempt to avoid overfitting in the model. You'll notice this take effect as the model stops training well before the 600 set epochs. ...
Read More

Choosing the right number of layers/neurons for a Neural Network (Python)

This seems to be a very confusing subject for most, and I've had difficulty while learning how to setup Keras NN models as the addition/subtraction of layers and neurons creates vastly different outcomes in model. Normally I wouldn't just link out to others, but there is a very well written synopsis found on StackExchange below that lays it out in a very simple fashion. Very brief summary: Input (first) layer: Neurons = Number of features in the datasetHidden layer(s): Neurons = Somewhere between 1 and the amount in the input later (take the mean); Number of hidden layers: 1 works for *most* applications, maybe none.Output (last) layer: exactly 1 unless it's a classification problem and you utilize the softmax activation, in which case the number equals the number of classes you are predicting https://stats.stackexchange.com/questions/181/how-to-choose-the-number-of-hidden-layers-and-nodes-in-a-feedforward-neural-netw Meaning in the case of a dataset with 20 features: #Example Keras Binary Classification model model = Sequential() model.add(Dense(20, activation='relu')) model.add(Dense(10, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy',optimizer='adam') #Example Keras Multi-Class model model = Sequential() model.add(Dense(20, activation='relu')) model.add(Dense(10, activation='relu')) model.add(Dense(3, activation='softmax')) #If I...
Read More

Keras and Tensorflow Pt II – Regression Example

This is a more complex example of Keras, utilizing Regression. This utilizes a good sized dataset from Kaggle, but does contain a little bit of data cleansing before we can build out the model. Unfortunately the model we end up building isn't perfect and requires more tuning or some final dataset alterations, but it's a good example none the less. More information below. ...
Read More

Kaggle Submission: Titanic

I've already briefly done some work in the dataset in my tutorial for Logistic Regression - but never in entirety. I decided to re-evaluate utilizing Random Forest and submit to Kaggle. In this dataset, we're utilizing a testing/training dataset of passengers on the Titanic in which we need to predict if passengers survived or not (1 or 0). ...
Read More

Grand Totals and Subtotals in SQL Server

Just one of those things you may not know existed - the ROLLUP clause. It's very useful for totaling. Are you used to doing something like this? SELECT customer, sum(sales) from table UNION SELECT 'Total', sum(sales) from table The problem here is that on larger datasets, this can really be a pain in terms of performance. ROLLUP can be extremely quick, but the syntax may not be straight forward. Here's an example of summing sales in AdventureWorks2017 with a Grand Total. USE AdventureWorks2017 SELECT SalesOrderID, sum(LineTotal) FROM Sales.SalesOrderDetail where SalesOrderID in ( '43659', '43660', '43661', '43662', '43663' ) GROUP BY SalesOrderID WITH ROLLUP Notice I've added a WITH ROLLUP at the end of my GROUP BY. This creates the grand total. However, I'm left with a NULL for the SalesOrderID. To solve this I wouldn't want to use a coalesce, because a NULL might be valid elsewhere. Instead we should use the GROUPING function. USE AdventureWorks2017 SELECT CASE WHEN GROUPING(SalesOrderID) = 1 THEN 'Total' ELSE cast(SalesOrderID as nvarchar(10)) END as SalesOrderID, sum(LineTotal) FROM Sales.SalesOrderDetail where SalesOrderID in ( '43659', '43660', '43661', '43662', '43663' ) GROUP BY SalesOrderID WITH ROLLUP You can extend this even further...
Read More
SQL Tips/Tricks
Warning: Trying to access array offset on value of type bool in /home/public/wp-content/themes/square/inc/template-tags.php on line 138

Natural Language Processing in Python – Simple Example

NLP is a huge deal recently, and quite "easy" to do on a basic level within Python. In this exercise I completed, we'll show how to classify yelp reviews both with and without text pre-processing. Interesting to note that the pre-processing actually didn't help us here. ...
Read More

Search all tables and views for column name in SQL Server

A nifty little bit of code I've used for years and years, very useful if you don't have a third party add-on installed... USE AdventureWorks2017 SELECT * FROM ( SELECT t.name AS name, 'table' as type, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%Employee%' UNION SELECT v.name AS name, 'view' as type, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.views AS v INNER JOIN sys.columns c ON v.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%Employee%' ) a ORDER BY schema_name, name ...
Read More
SQL Tips/Tricks
Warning: Trying to access array offset on value of type bool in /home/public/wp-content/themes/square/inc/template-tags.php on line 138

Error Catching – Stored Procedure inside of SSIS

One fun thing I found out about SSIS is that is doesn't always error out a package if you execute stored procedures as SQL tasks instead of utilizing the SQL itself inside of the package. In other words - it may produce an error if you were to execute it in SSMS, but if you execute within SSIS it'll fly by successfully without you knowing anything went wrong. The best little trick I've found is to just surround the entire procedure with a Try/Catch block. This seems to raise the error up to SSIS and fails the package for you. CREATE PROCEDURE usp_TestProc as BEGIN TRY --SQL goes here... END TRY BEGIN CATCH PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + ' at line ' + CONVERT(varchar(50), ERROR_LINE()) + ': ' + ERROR_MESSAGE(); END CATCH; GO ...
Read More
SQL Tips/Tricks,
Warning: Trying to access array offset on value of type bool in /home/public/wp-content/themes/square/inc/template-tags.php on line 138

Including Jupyter Notebooks on WordPress – Part II

An update to a post I wrote in July of 2020 about embedding Jupyter Notebooks on WordPress. The original post is located here. I continued along utilizing the nbconvert shortcode for a while and encountered a huge amount of problems with https://nbviewer.jupyter.org/. Essentially - I believe there is some sort of bug with the system. Normally it takes 1-2 days for nbviewer to "recognize" something that is dropped into github - which isn't a huge deal but a big annoyance. In addition - I've had multiple workbooks go 1-2 weeks without being recognized, and a few that were fine and then dropped into a 404 error on the site. Either way - I'm looking at using a great little utility called "nb2wp" and located on github here. All it really does is perform the same conversion, but drops it locally to a .html file with CSS inline, along with saving all of the images (and embeds the links to those images as...
Read More
Python Tips/Tricks,
Warning: Trying to access array offset on value of type bool in /home/public/wp-content/themes/square/inc/template-tags.php on line 138