Scraping Nonograms to build a solver using machine learning

Posted on Aug 12, 2018

What and Why?

Nonograms are logic puzzles that create an image when solved. Originally invented in the 1980's by two different people simultaneously, and became popular in the late 80s-90s. Now they're known by almost 30 different names, the most popular ones being nonograms, hanjie puzzles, picross puzzles, and griddlers. The clues on the side and top denote which squares should be empty or filled in. The numbers denote the black squares and each group of black squares must be separated by at least one empty space. Here's a really simple puzzle being solved step-by-step.

Each move has a reason and nothing is a guess. My dad, after ordering a book of puzzles, thought they might be a good machine learning project. So this web scraping project is the first step of building a nonogram solver using machine learning.

Scraping code

From this website: I scraped around 8K puzzles for the size, clues, solutions, and difficulty of the puzzles. The biggest issue I came across was scraping the actual clues themselves. The actual table was hidden behind the javascript and I couldn't scrape it like everything else in the html. My solution to this was using scrapy_splash in my spider as a work around as was able to the clues as a list of empty spaces and numbers. Here is the data and its corresponding puzzle.

sizeCol 14
sizeRow 16
title Snail
number 15868
difficulty 5
colClues  , , ,1,1, , , ,1,1, , , , ,3, , , , ,4, , , , ,4, , , ,2,6, , ,2,2,2, , ,4,2,2, ,3,1,2,1,1,2,2,1,1, ,1,1,2,1, , ,2,4,1, , ,2,1,2, , , ,7,4
rowClues  , , , , , , , ,1, , , , , , , , , , , , , , ,1,1,1, , , , , , , , , , ,1,2,2,2,1,2,1, ,2, , , ,1, , ,8,3,2,1,1,1,2,3,2,1,4, , ,2,4,10,2,2,1,1,1,1,1,1,1,1,2,2,1
size  224

For my code and data, visit my GitHub Page:

What's next?

  1. Convert output images (solutions) into data which becomes the Y value
  2. Split input data set into training set and test set (90:10)
  3. Use the training set to train a few statistical machine learning algorithms
  4. Use the test set to test the trained model
  5. If the accuracy is good enough, use the model to predict answers for new puzzles.
  6. Areas of research: Use neural networks to find answers instead of statistical models

About Author

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp